PDA

View Full Version : php support needed


TheSupportForum
10-27-2012, 07:23 PM
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


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

kh99
10-27-2012, 09:26 PM
You could use the vbulletin function print_standard_redirect():

// ################################################## ###########################
/**
* 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)

{

TheSupportForum
10-27-2012, 10:01 PM
You could use the vbulletin function print_standard_redirect():

// ################################################## ###########################
/**
* 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

$redir_phrase = $vbulletin->options['myredirect'];

would this be what i need to do ?

kh99
10-27-2012, 10:13 PM
so the $redir_phrase its self will become the URL ?
if so, all i need to do is register the variable as follows

$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:
$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.

TheSupportForum
10-27-2012, 10:31 PM
i am not sure if you understand

all my functions are called as

function blockAccess

these are the badcookies
global $forbidbad, $badcookie

this is the full 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


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
function blockAccess

i need it to actually redirect to a chosen URL thats in this variable

$myredir = $vbulletin->options['redirecturl'];

kh99
10-27-2012, 10:37 PM
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:
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');
}

TheSupportForum
10-27-2012, 10:43 PM
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:
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 ';'

kh99
10-27-2012, 10:44 PM
oops - it had a typo, it was missing a ';'. I fixed it in my post above.

TheSupportForum
10-27-2012, 11:06 PM
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

The page isn't redirecting properly

and it does redirect the the url i want :(

kh99
10-27-2012, 11:09 PM
The page isn't redirecting properly

Is that a message from somewhere else in your code?

Edit: Maybe try this:

print_standard_redirect('phrase_to_show', true, false, -1, true);

TheSupportForum
10-27-2012, 11:19 PM
Is that a message from somewhere else in your code?

Edit: Maybe try this:

print_standard_redirect('phrase_to_show', true, false -1, true);

Warning: Cannot modify header information - headers already sent by (output started at /includes/class_bootstrap.php(996) : eval()'d code:108) in /includes/class_bootstrap.php(996) : eval()'d code on line 96

Warning: Cannot modify header information - headers already sent by (output started at /includes/class_bootstrap.php(996) : eval()'d code:108) in /includes/class_bootstrap.php(996) : eval()'d code on line 97



i am just wondering if this is due to me running this in a plugin, or if i need to register the vbulletin cookie ?

kh99
10-27-2012, 11:24 PM
Well, I made another typo and left out a comma - it should have been:
print_standard_redirect('phrase_to_show', true, false, -1, true);


But that error message you posted happens if your code produces any output before you call print_standard_redirect(). I probably shoudlhave started out by asking, where are you calling your function from? Is it a custom script or a plugin?

TheSupportForum
10-27-2012, 11:29 PM
Well, I made another typo and left out a comma - it should have been:
print_standard_redirect('phrase_to_show', true, false, -1, true);
But that error message you posted happens if your code produces any output before you call print_standard_redirect(). I probably shoudlhave started out by asking, where are you calling your function from? Is it a custom script or a plugin?

The page isn't redirecting properly

detected that the server is redirecting the request for this address in a way that will never complete.

it redirects as should but shows that error in the browser

kh99
10-27-2012, 11:35 PM
Do you know what $myredir is set to? Maybe try this: temporarily add this code before the call to print_standard_redirect:

die("redirect to '$myredir'");

TheSupportForum
10-28-2012, 12:02 AM
Do you know what $myredir is set to? Maybe try this: temporarily add this code before the call to print_standard_redirect:

die("redirect to '$myredir'");

i am still getting

Warning: Cannot modify header information - headers already sent by (output started at [path]/global.php(29) : eval()'d code:424) in [path]/includes/class_bootstrap.php(996) : eval()'d code on line 96

Warning: Cannot modify header information - headers already sent by (output started at [path]/global.php(29) : eval()'d code:424) in [path]/includes/class_bootstrap.php(996) : eval()'d code on line 97

kh99
10-28-2012, 12:15 AM
Is your plugin using hook global_start? Try looking at what's on line 424 (that might not be the right line because it includes all plugins using hook global_start).

TheSupportForum
10-28-2012, 12:42 AM
Is your plugin using hook global_start? Try looking at what's on line 424 (that might not be the right line because it includes all plugins using hook global_start).

looks like its not gonna work they way i need it so i thought about this

if (!$vbulletin->options['agturnoff'])

eval(standard_error($vbulletin->options['agblacklistmessage']



how would i change it, instead of

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');
}

--------------- Added 1351389136 at 1351389136 ---------------

right i must get some other work done, i've learn a lot tonight and i'm feeling tired