Old 22-01-2008, 18:59   #1 (permalink)
Kaklz
Rock it out.
 
Kaklz's Avatar
 
Join Date: Dec 2007
Posts: 209
Recognition of previous page.

Hey all. Is there a way to make a page that knows which page referred to it?
I'll illustrate: Page a and page b both link to page c. I want to set it up so that if one went to page c from page a, clicking a button like "continue" sends one to page d, whereas if one got to page c from page b, clicking "continue" would bring you to page e.
I really hope that that made sense.
Diagram:
Page A > Page C >click "continue" > Page D
Page B > Page C >click "continue" > Page E
Is this possible?
  Reply With Quote
Old 22-01-2008, 19:05   #2 (permalink)
cjgraphix
Website Developer
 
cjgraphix's Avatar
 
Join Date: Jun 2007
Location: Pacific Northwest
Posts: 413
php $_SERVER['HTTP_REFERER']; will tell you where it came from.
__________________
  Reply With Quote
Old 22-01-2008, 23:13   #3 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,605
to elaborate on that, you can use this code for your <a> tag:
Code:
<a <?php if ($_SERVER['HTTP_REFERER'] == "page_a") { echo "href=\"page_d\""; } elseif ($_SERVER['HTTP_REFERER'] == "page_b") { echo "href=\"page_e\""; } ?>>continue</a>

Just change around the page names.
  Reply With Quote
Old 23-01-2008, 07:42   #4 (permalink)
MikeMackay
Everything is fine.
 
MikeMackay's Avatar
 
Join Date: Feb 2005
Location: Witham & London
Posts: 828
Send a message via MSN to MikeMackay Send a message via Skype™ to MikeMackay
Just be advised though that this is not 100% reliable as some browsers (and even routers) can remove this header from the requesting user agent. This is also easy to spoof if needed.

Generally though, for non mission-critical applications this method should suffice.

Always good to be aware of what could go wrong.

- Mike

Last edited by MikeMackay : 23-01-2008 at 11:39.
  Reply With Quote
Old 23-01-2008, 08:11   #5 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,605
The best way is to indicate the referring page is either through a $_POST method or a $_GET method. Cookies can be used as well, but if the user has cookies turned off/blocked on their machine, it wont work.
  Reply With Quote
Old 28-01-2008, 16:04   #6 (permalink)
Kaklz
Rock it out.
 
Kaklz's Avatar
 
Join Date: Dec 2007
Posts: 209
Quote:
Originally Posted by haku
to elaborate on that, you can use this code for your <a> tag:
Code:
<a <?php if ($_SERVER['HTTP_REFERER'] == "page_a") { echo "href=\"page_d\""; } elseif ($_SERVER['HTTP_REFERER'] == "page_b") { echo "href=\"page_e\""; } ?>>continue</a>

Just change around the page names.
Thanks a lot.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8