Redirect only if coming from specific page

I need users redirected to a specific page but only if coming from another specific page.  I am running apache, php.  

Thanks!
Large_FarvaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Use document.referrer : http://www.w3schools.com/jsref/prop_doc_referrer.asp


<script>
if( document.referrer.indexOf("google.com") >= 0 ) {
      location.reload = "http://www.experts-exchange.com";
}
</script>

Open in new window

0
asadhaiderCommented:
The above code uses javascript, using PHP code would be much better for your site. The following code will work, the referrer variable stores the referring page and the if statements check that referrer and match it against site1.com, site2.com and redirect if matches are made.

If you give the exact referring page which you want redirected and the page the redirect should go to, then I'll modify the code above if you want.
<?php
$referrer = $_SERVER['HTTP_REFERER'];

if (preg_match("/site1.com/",$referrer)) {
      header('Location: http://www.customercare.com/page-site1.html');
} elseif (preg_match("/site2.com/",$referrer)) {
      header('Location: http://www.customercare.com/page-site2.html');
} else {
      header('Location: http://www.customercare.com/home-page.html');
}
?>

Open in new window

0
Large_FarvaAuthor Commented:
Thanks for the help!

@asadhaider:  Here is what I need:
If someone comes from http://www.mydomain.com/registration/ 
then
redirect to http://www.mydomain.com/folder/

Thanks!
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

asadhaiderCommented:
This should do the trick. Change the values of "mydomain.com" and "folder" only, to what your domain is (leave the www. out).
<?php
$referrer = $_SERVER['HTTP_REFERER'];

if (preg_match("/mydomain.com\/registration\//",$referrer)) {
      header('Location: http://www.mydomain.com/folder/');
}
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Large_FarvaAuthor Commented:
Not working yet.  I put the above code with my changes above everything in the header file of my cms.  Is that the right location?

0
Large_FarvaAuthor Commented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.