Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-27-2012, 07:23 PM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default php support needed

i have been working on a script for a few weeks now, and nearly at
final stages of releasing it, but i need help with the following

PHP Code:
function blockAccess($message) {
    global 
$forbidbad$badcookie$myredir;
    if (
$forbidbad == true) {
        
writeCookie($badcookie$message$myredir);
    } 
i want to insert a redirect script / code into this
basically the above writes a cookies to block access, so the idea is if the statement above is true the redirect to a given $varaiable set in admincp
Reply With Quote
  #2  
Old 10-27-2012, 09:26 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could use the vbulletin function print_standard_redirect():

Code:
// #############################################################################
/**
* Returns eval()-able code to initiate a standard redirect
*
* The global variable $url should contain the URL target for the redirect
*
* @param	mixed	Name of redirect phrase, or array if constructing a phrase.
* @param	boolean	If false, use the name of redirect phrase as the phrase text itself
* @param	boolean	Whether or not to force a redirect message to be shown
* @param	integer	Language ID to fetch the phrase from (-1 uses the page-wide default)
* @param	bool	Force bypass of domain whitelist check
*
* @return	none (the session is re-directed).
*/
function print_standard_redirect($redir_phrase, $isphrase = true, $forceredirect = false, $languageid = -1, $bypasswhitelist = false)

{
Reply With Quote
  #3  
Old 10-27-2012, 10:01 PM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
You could use the vbulletin function print_standard_redirect():

Code:
// #############################################################################
/**
* Returns eval()-able code to initiate a standard redirect
*
* The global variable $url should contain the URL target for the redirect
*
* @param    string    Name of redirect phrase
* @param    boolean    If false, use the name of redirect phrase as the phrase text itself
* @param    boolean    Whether or not to force a redirect message to be shown
* @param    integer    Language ID to fetch the phrase from (-1 uses the page-wide default)
*
* @return    string
*/
function print_standard_redirect($redir_phrase, $doquery = true, $forceredirect = false, $languageid = -1)
{
so the $redir_phrase its self will become the URL ?
if so, all i need to do is register the variable as follows

PHP Code:
$redir_phrase $vbulletin->options['myredirect']; 
would this be what i need to do ?
Reply With Quote
  #4  
Old 10-27-2012, 10:13 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by simonhind View Post
so the $redir_phrase its self will become the URL ?
if so, all i need to do is register the variable as follows

PHP Code:
$redir_phrase $vbulletin->options['myredirect']; 
would this be what i need to do ?
Oh, right, I should have mentioned: you would set $vbulletin->url to the url, like:
Code:
$vbulletin->url = $vbulletin->options['myredirect'];
print_standard_redirect($redir_phrase);

That assumes that $redir_phrase is a phrase name. If it's the actual text, then you would want the second parameter to print_standard_redirect to be false (it's true by default).

Also, print_standard_redirect will use http headers to do a redirect so that the user won't see the message unless their browser doesn't support header redirects (I have no idea if that even happens at all these days). If you want to be sure that the message is displayed, use true for the third parameter.

Edit: also I forgot that I had the vb3 code loaded when I copied the description of print_standard_redirect() above - I replaced it with the vb4 version. This brings up another issue: if you're redirecting to a url that isn't part of your site, you might need to set the "bypasswhitelist" parameter to true.
Reply With Quote
  #5  
Old 10-27-2012, 10:31 PM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i am not sure if you understand

all my functions are called as

PHP Code:
function blockAccess 
these are the badcookies
PHP Code:
global $forbidbad$badcookie 
this is the full code
PHP Code:
function blockAccess($message) {
    global 
$forbidbad$badcookie$myredir;
    if (
$forbidbad == true) {
        
writeCookie($badcookie$message$myredir);
    }
    echo
    <<<HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>403 Forbidden</title>
<meta name="robots" content="noindex" />

</head>
<BODY>

<H1>! Forbidden !</H1>

<BR>
<P>You have been taken to this page for a reason :
<P>A) your a bad bot.
<P>B) you maybe a spammer.
<P>C) You may of been blacklisted

</BODY>
</html>
HTML;
    die();

i want to remove

PHP Code:
    echo
    <<<HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>403 Forbidden</title>
<meta name="robots" content="noindex" />

</head>
<BODY>

<H1>! Forbidden !</H1>

<BR>
<P>You have been taken to this page for a reason :
<P>A) your a bad bot.
<P>B) you maybe a spammer.
<P>C) You may of been blacklisted

</BODY>
</html>
HTML;
    die();

so that i can create a redirect using my current function
PHP Code:
function blockAccess 
i need it to actually redirect to a chosen URL thats in this variable

PHP Code:
$myredir $vbulletin->options['redirecturl']; 
Reply With Quote
  #6  
Old 10-27-2012, 10:37 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't know if I understand either. Are you not able to call print_standard_redirect(), or is it that you don't think it does what you want? Why not this:
Code:
function blockAccess($message) {
    global $forbidbad, $badcookie, $myredir;
    if ($forbidbad == true) {
        writeCookie($badcookie, $message, $myredir);
    }
    
    global $vbulletin;
    $vbulletin->url = $myredir;
    print_standard_redirect('phrase_to_show');
}
Reply With Quote
  #7  
Old 10-27-2012, 10:43 PM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
I don't know if I understand either. Are you not able to call print_standard_redirect(), or is it that you don't think it does what you want? Why not this:
Code:
function blockAccess($message) {
    global $forbidbad, $badcookie, $myredir;
    if ($forbidbad == true) {
        writeCookie($badcookie, $message, $myredir);
    }
    
    global $vbulletin
    $vbulletin->url = $myredir;
    print_standard_redirect('phrase_to_show');
}
i get this with the above

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';'
Reply With Quote
  #8  
Old 10-27-2012, 10:44 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

oops - it had a typo, it was missing a ';'. I fixed it in my post above.
Reply With Quote
  #9  
Old 10-27-2012, 11:06 PM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
oops - it had a typo, it was missing a ';'. I fixed it in my post above.

ok i have some progress but now i am getting

PHP Code:
The page isn't redirecting properly 
and it does redirect the the url i want
Reply With Quote
  #10  
Old 10-27-2012, 11:09 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by simonhind View Post
PHP Code:
The page isn't redirecting properly 
Is that a message from somewhere else in your code?

Edit: Maybe try this:

Code:
   print_standard_redirect('phrase_to_show', true, false, -1, true);
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:28 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04096 seconds
  • Memory Usage 2,281KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_code
  • (11)bbcode_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete