PHP referrer redirect script help. just need this tweaked a little

turbotec

BANNED
Joined
Apr 5, 2008
Messages
181
Reaction score
15
so I am currently using a php script to check referrer and then redirect accordingly.

Code:
<?php
	$referer = $_SERVER['HTTP_REFERER'];
	if($referer == "http://www.mysite.com/test/testreferrerredirect.php")
	{
		echo '<meta http-equiv="refresh" content="0;url=http://www.pyromosh.org/images/bbs/have_a_cookie.gif">';
	}
	else
	{
		echo '<meta http-equiv="refresh" content="0;url=http://www.youfail.org/">';	
	}
?>



SO, right now if the referrer is "http://www.mysite.com/test/testreferrerredirect.php" than it will do what I want. Here is my question though. I want it to redirect to the correct site IF the referrer is anywhere from "mysite.com" not just the php page above. does this make sense?? I tried just making the value equal "http://www.mysite.com/" but it didnt work. how can I change the script to redirect if it is coming from anywhere on the mysite.com page??
 
PHP:
<?php
	$referer = $_SERVER['HTTP_REFERER'];
	if(preg_match("/www.mysite.com/i", $referer))
	{
		echo '<meta http-equiv="refresh" content="0;url=http://www.pyromosh.org/images/bbs/have_a_cookie.gif">';
	}
	else
	{
		echo '<meta http-equiv="refresh" content="0;url=http://www.youfail.org/">';	
	}
?>
 
hey alright that works good. now one more question relating to the same thing. how can i get it to work from only http://www.mysite.com/test ?


sorry Im so bad at this PHP stuff.
 
Last edited:
Just change:

PHP:
"/www.mysite.com/i"

to:
PHP:
"/www.mysite.com/test/i"

That's a followed by a /. The is just an escape character telling php to treat the next / as part of the string it's testing for a match instead of the end of the string initiated by the / after the first quote.

On a side note, my brain hurts. :)

edit Bleh. the board is interpreting things too.

Take out all the asterisks: "/ww*w.*mysite.*c*om**/test/i"

double edit. Dammit. I don't have any idea how to force it to let me give you the code. lol

I'll have to fight with it a bit. Might be easier just attach a file. Give me a sec.

edit the last time: try this file. rofl.
 

Attachments

Last edited:
ok I get it. thanks a ton man!! this is similar a regex when writing in VB code!!
 
yes it is regular expresion. very powerful tool for matching strings.
 
ok so now how can I add a list of good referrers? do you just stack them up? for example:

PHP:
<?php
    $referer = $_SERVER['HTTP_REFERER'];
    if(preg_match("/www.mysite.com/i", $referer))
    if(preg_match("/www.yoursite.com/i", $referer))
    if(preg_match("/www.hissite.com/i", $referer))
    if(preg_match("/www.hersite.com/i", $referer))
        {
        echo '<meta http-equiv="refresh" content="0;url=http://www.pyromosh.org/images/bbs/have_a_cookie.gif">';
    }
    else
    {
        echo '<meta http-equiv="refresh" content="0;url=http://www.youfail.org/">';    
    }
?>

would that be an effective way to add multiple good referrers to accept or is there a better way?
 
bump.....this code is working great for me with just one referrer....but like i said above, how can I get it to look for 1 of say 4 referrers and then continue on with the code?
 
PHP:
<?

if((preg_match("/www.hersite.com/i", $referer)) OR (preg_match("/www.hissite.com/i", $referer)) OR (preg_match("/www.yoursite.com/i", $referer)) OR (preg_match("/www.mysite.com/i", $referer)))//if referer is one of this 4
        {

        echo '<meta http-equiv="refresh" content="0;url=http://www.pyromosh.org/images/bbs/have_a_cookie.gif">';

    }

    else

    {

        echo '<meta http-equiv="refresh" content="0;url=http://www.youfail.org/">';    

    }


	
?>
 
that did it thanks guys. one day I will be as good at php as you guys.
 
Back
Top