sleith Posted October 21, 2008 Share Posted October 21, 2008 i wanna ask what technique to redirect a page with multiple tab window? i use session to track page and redirection. but this is will fail if there's more than one window tab, because the session value will be overwritten. thx Quote Link to comment https://forums.phpfreaks.com/topic/129354-url-redirection/ Share on other sites More sharing options...
sKunKbad Posted October 21, 2008 Share Posted October 21, 2008 Show some code so we can try to figure out what you are doing. Quote Link to comment https://forums.phpfreaks.com/topic/129354-url-redirection/#findComment-670613 Share on other sites More sharing options...
sleith Posted October 21, 2008 Author Share Posted October 21, 2008 here's my sample code : topic_detail.php -> this is like the topic we see in forum, and there's a reply link. This url is saved into session using getThisURL function. <?php session_start(); $_SESSION['lastURL'] = getThisURL(); ?> <a href='write_reply.php?id=1'>Write reply</a> write_reply.php -> this will process the reply saved into database etc. and after process, will be redirect into redirect.php <?php session_start(); //do processing... header("Location: redirect.php"); ?> redirect.php -> this is the page where will take care all redirection. This url will be taken from the session value. <?php session_start(); if( isset($_SESSION['lastURL']) ){ header("Location:" . $_SESSION['lastURL']); } ?> With that code, relying on session, will fail if user browse in multiple tabs thanks Quote Link to comment https://forums.phpfreaks.com/topic/129354-url-redirection/#findComment-670617 Share on other sites More sharing options...
blueman378 Posted October 21, 2008 Share Posted October 21, 2008 why not as soon as the page loads grab the data from the session and store it in another variable on that page then when redirecting back just refernece that variable, i mean who is going to open another tab on your site within the miliseconds it takes to grab that session? Quote Link to comment https://forums.phpfreaks.com/topic/129354-url-redirection/#findComment-670639 Share on other sites More sharing options...
sKunKbad Posted October 21, 2008 Share Posted October 21, 2008 What browser? Having other tabs open shouldn't matter. I use a redirect script that is similar to what you have here, and it isn't affected by tabbed browsers (FF3, FF3, OPERA, IE7) Quote Link to comment https://forums.phpfreaks.com/topic/129354-url-redirection/#findComment-670640 Share on other sites More sharing options...
sleith Posted October 21, 2008 Author Share Posted October 21, 2008 why not as soon as the page loads grab the data from the session and store it in another variable on that page then when redirecting back just refernece that variable, i mean who is going to open another tab on your site within the miliseconds it takes to grab that session? it can't be done because im using session, no passing values. it's no use if i grab the session data, because what will i do with the variable? except that i pass the value with url or hidden text What browser? Having other tabs open shouldn't matter. I use a redirect script that is similar to what you have here, and it isn't affected by tabbed browsers (FF3, FF3, OPERA, IE7) could you post your sampe code? i think it's impossible if the value is not overwritten. imagine i visit topic_a, the session value will be "topic_a". and then i open a new tab and visit topic_b, and the session value will be overwritten "topic_b" and then i reply on topic_a and redirect with value "topic_b" Quote Link to comment https://forums.phpfreaks.com/topic/129354-url-redirection/#findComment-670641 Share on other sites More sharing options...
blueman378 Posted October 21, 2008 Share Posted October 21, 2008 Ah good point on sessions; each tab is considered a different session i believe Quote Link to comment https://forums.phpfreaks.com/topic/129354-url-redirection/#findComment-670642 Share on other sites More sharing options...
sleith Posted October 21, 2008 Author Share Posted October 21, 2008 Ah good point on sessions; each tab is considered a different session i believe yes, something like that. is that possible? i think it can be done if using javascript cookie. but i would like not to depend on javascript, because people may disable javascript Quote Link to comment https://forums.phpfreaks.com/topic/129354-url-redirection/#findComment-670648 Share on other sites More sharing options...
sKunKbad Posted October 22, 2008 Share Posted October 22, 2008 i think it can be done if using javascript cookie. but i would like not to depend on javascript, because people may disable javascript On my site, I have a theme switcher that uses a session cookie. I opened my site in two tabs, switched the theme in one tab, went to the other tab, and that tab used the session cookie from the first tab. I tested in FF2, FF3, Opera 9.27, IE7, and Safari 3.1.1 on Windows. I didn't check my Mac or Linux browsers, but you shouldn't have any problems with those either. Please show your getThisURL() function, and more code if possible. The problem you are having is almost certainly a result of your code, and not the normal behavior of session cookies. Quote Link to comment https://forums.phpfreaks.com/topic/129354-url-redirection/#findComment-671412 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.