|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Redirection + cookie
Hi,
I set up a cookie to force the visitors to pass through my index.php page. On each other pages (html) of my site, I check if the cookie exists, and if not I redirect the visitor to my index page. This index.php logs some information and set the cookie, then the visitor is redirected to my news.html page. Now, I'd like to know how I can redirect the visitor (in my index.php) depending on where he came. I mean if he come from the www.mysite.com, then he is redirected to my news.htm page, BUT if he came through a bookmark or entered an URL to a different page of my site, I'd like to redirect him to the address he enter at the beginning, before checking if the cookie exist. How can I do that? Here is my javascript code that redirects the visitors to the news.htm page after setting the cookie. Code:
<SCRIPT language="javascript">
SetCookie("index","1",date_exp,myDomain);
window.location="news.htm";
</SCRIPT>
Thanks |
|
#2
|
||||
|
||||
|
RE: Redirection + cookie
I checked quick in my O'Reilly JavaScript book and they recommend the following:
Code:
<script>
// If linked from somewhere
// offsite, go to home page first.
if (document.referrer == "" ||
document.referrer.indexOf("mysite.com") == -1)
window.location="http://home.mysite.com";
</script>
Of course an obvious flaw with this is that it doesn't work for browsers that dont' support JavaScript or have it turned off. I do my redirections server-side. -Tim |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > Redirection + cookie |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|