1

I want to redirect my site visitors form page B using my custom PHP script following this rule: If they come from page A, will be redirected to url 1, else i will display content/or url 2. I use this:

 <?php
$referer = $_SERVER['HTTP_REFERER'];
$rest = substr("$referer", -8);
if($rest == "send.php")// if they come from my website page "send.php"
{
echo "<meta http-equiv=\"refresh\" content=\"0;url=http://google.com\">"; 
}
else
{
echo "$rest";
include 'content.php'; 
}
?>

. Anyone can help?

1
  • why you can't use header and then check? Commented Jun 14, 2015 at 19:53

1 Answer 1

2
<?php
$referer = $_SERVER['HTTP_REFERER'];
if (strpos($referer,'send.php') !== false) 
{
echo "<meta http-equiv=\"refresh\" content=\"0;url=http://google.com\">"; 
}
else
{
echo "$rest";
include 'content.php'; 
}
?>

Instead of meta redirect you can also use header location.

header("Location:http://www.google.com");
Sign up to request clarification or add additional context in comments.

1 Comment

Thx, i use meta redirect because i want to keep the referer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.