vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   php support needed (https://vborg.vbsupport.ru/showthread.php?t=289743)

TheSupportForum 10-27-2012 07:23 PM

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

kh99 10-27-2012 09:26 PM

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)

{


TheSupportForum 10-27-2012 10:01 PM

Quote:

Originally Posted by kh99 (Post 2376412)
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 ?

kh99 10-27-2012 10:13 PM

Quote:

Originally Posted by simonhind (Post 2376419)
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.

TheSupportForum 10-27-2012 10:31 PM

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']; 


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


TheSupportForum 10-27-2012 10:43 PM

Quote:

Originally Posted by kh99 (Post 2376427)
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 ';'

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

Quote:

Originally Posted by kh99 (Post 2376431)
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 :(

kh99 10-27-2012 11:09 PM

Quote:

Originally Posted by simonhind (Post 2376432)
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);

TheSupportForum 10-27-2012 11:19 PM

Quote:

Originally Posted by kh99 (Post 2376433)
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);

Code:

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:
Code:

  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

Quote:

Originally Posted by kh99 (Post 2376437)
Well, I made another typo and left out a comma - it should have been:
Code:

  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?

Code:

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:

Code:

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

TheSupportForum 10-28-2012 12:02 AM

Quote:

Originally Posted by kh99 (Post 2376440)
Do you know what $myredir is set to? Maybe try this: temporarily add this code before the call to print_standard_redirect:

Code:

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

Quote:

Originally Posted by kh99 (Post 2376444)
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

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


--------------- Added [DATE]1351389136[/DATE] at [TIME]1351389136[/TIME] ---------------

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


All times are GMT. The time now is 04:54 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.01909 seconds
  • Memory Usage 1,815KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (13)bbcode_code_printable
  • (12)bbcode_php_printable
  • (9)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (17)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete