Forum Moderators: coopster

Message Too Old, No Replies

PHP/Javascript Cookies access

Direct user to some page when they click Browser Back Button!

         

smagdy

8:39 pm on Mar 21, 2006 (gmt 0)

10+ Year Member



Hello everybody,

I want to achieve something but i cant figure out how!

1- User submit form (DONE)
2- Set Cookie/variable or whatever other (PHP/JS) solution after form submission (Not Done)
3- User click the Browser Back Button
4- I check if cookie/variable was set then i direct user to some other page!

I just want the algorith and the tool ... not necessary the code :)

Also is it possible to set php cookie after the page is submitted then check it by javascript on 2nd page by using

<body onLoad=CheckPhpCookie();>

Anyways in Short all i want is that i direct the user to some page when they click the Browser Back Button after form submission!

Thanks in advance

mrnoisy

5:11 am on Mar 22, 2006 (gmt 0)

10+ Year Member



Put this on page that comes after the back button, after the cookie has been set by the previous page:

if(isset($HTTP_COOKIE_VARS['cookie_id'])) {
header("Location: http*://www.redirect.com/");
exit;
}

It will check for the cookie, and if set will redirect to www.redirect.com

Tastatura

6:59 am on Mar 22, 2006 (gmt 0)

10+ Year Member



Also is it possible to set php cookie after the page is submitted then check it by javascript on 2nd page by using
<body onLoad=CheckPhpCookie();>

I think that it should be possible. Part of my cookie routine consists of setting cookie via JS, but then reading it via PHP on the second page
HTH

smagdy

8:27 am on Mar 22, 2006 (gmt 0)

10+ Year Member



Nothing Works!

Because when i click the Browser Back Button of IE 6, it just go there without refreshing the page.. it just go to the cache and i tried several codes to refresh it but i failed..

So maybe u can give me the right code to refresh it once the back button was pressed ....

Thanks

smagdy

8:29 am on Mar 22, 2006 (gmt 0)

10+ Year Member



I am having this at the very top of the page.......

<?php
session_start();
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

then i added this now but no reaction but the cached page....

if(isset($HTTP_COOKIE_VARS['TestCookie'])) {
header("Location: http*://www.redirect.com/");
exit;
}

smagdy

8:48 am on Mar 22, 2006 (gmt 0)

10+ Year Member



By the way they all work fine as i want in all other browsers ex. Netscape, Firefox.... without anyheader or anything..

When i pres the back button they display message that the previous page contains POST data that are expired from the Cache... So it refresh the page and then i redirect it because there is session that doesnt exit after the submission... but IE6 cache everything no matter what...

I am sure that all developers faces same problem with IE cache but hopefully there exist the solution!

Thanks again

Tastatura

8:54 am on Mar 22, 2006 (gmt 0)

10+ Year Member



I am not sure, but part of your issue might be due to exit function ( I am not an PHP expert so …). Take a look at exit() page on [php.net ] for more info – also some of the posts on that page discuss headers as well.
For debugging purposes I would add
print_r($_COOKIE);

to the code just to see what is going on with cookies.
HTH