Jump to content

Referring URL redirect


JonEMD

Recommended Posts

Hello People,

 

I've been racking my brains, searching google and trawling through the many pages here to see if someone else has already asked the same question but I cant find it.

 

I'm trying to build a simple redirect script based on the referring URL.

 

I want to direct the user to "page a" if any of the arrays are found and "page b" if not.

 

This is what I have so far

 

<?php 

$main_string="@$HTTP_REFERER";

$arr = array('aaaa','bbbb','cccc');

foreach($arr as $key => $search_needle) {

if(stristr($main_string, $search_needle) != FALSE) 
{
echo "<meta http-equiv=Refresh content=0;url=http://www.google.com/PAGEA.html>";
}
} 

?>

 

I thought that it might be a case of adding the "else" command but doing that will always redirect to "page b" if all of the arrays aren't true and only 1 needs to be.

 

Anyone got any ideas?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/253573-referring-url-redirect/
Share on other sites

That makes sense but I'm not sure what to do with it.....

 

Currently, if any of the arrays match it goes to "page a" which is fine. The issue I have is if none of the arrays match nothing happens but I want it to redirect to "page b".

 

How can i code that? What function would I need to use?

 

Thanks

If you have code inside the loop that'll redirect if there's a match, right? So if you've left the loop nothing must have matched, right?

 

Be sure you exit; after each call to header. Which, by the way, you should be using to redirect instead of a META tag.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.