monkey_05_06 Posted December 12, 2006 Share Posted December 12, 2006 I'm fairly new to PHP (I've worked with it a bit in the past, but nothing really serious) and I've encountered something that's bugging me. It's not much really but I was just wondering if it's possible to redirect to another page without losing my variables. I'm using a bit of JavaScript to get information about the browser's width/height, but to get that into PHP I have to post the data.That's fine and I've gotten that figured out, the problem comes in if I want to use the included JS page as the action page of the form and redirect to the calling page instead of using the calling page as the action page. The problem with using the calling page as the action is that the POST data is then stuck to that page so if the user tries to refresh they get a message about POST data having been sent.If possible I'd like to be able to save the posted variables and then redirect back to the original page. If it's not possible I guess my users will just have to click their "go" button instead of refresh. Link to comment https://forums.phpfreaks.com/topic/30318-redirect-without-losing-variables-solved/ Share on other sites More sharing options...
TEENFRONT Posted December 12, 2006 Share Posted December 12, 2006 Use session vars. Link to comment https://forums.phpfreaks.com/topic/30318-redirect-without-losing-variables-solved/#findComment-139510 Share on other sites More sharing options...
monkey_05_06 Posted December 12, 2006 Author Share Posted December 12, 2006 I've set up my code like this:[code] $_SESSION["window_width"] = $_POST["window_width"]; $_SESSION["window_height"] = $_POST["window_height"]; header("Location: http://localhost/index2.php");[/code]But the session variables never seem to be getting set. Am I using this wrong? Link to comment https://forums.phpfreaks.com/topic/30318-redirect-without-losing-variables-solved/#findComment-139516 Share on other sites More sharing options...
trq Posted December 12, 2006 Share Posted December 12, 2006 You need to issue a call to [url=http://php.net/session_start]session_start[/url]() on both this page, and the page you redirect to. Link to comment https://forums.phpfreaks.com/topic/30318-redirect-without-losing-variables-solved/#findComment-139519 Share on other sites More sharing options...
monkey_05_06 Posted December 12, 2006 Author Share Posted December 12, 2006 AWESOME! Thanks to both of you for your help!!! Link to comment https://forums.phpfreaks.com/topic/30318-redirect-without-losing-variables-solved/#findComment-139535 Share on other sites More sharing options...
TEENFRONT Posted December 12, 2006 Share Posted December 12, 2006 <?Session_start(); $_SESSION["window_width"] = $_POST["window_width"]; $_SESSION["window_height"] = $_POST["window_height"]; header("Location: http://localhost/index2.php"); ?>and as suggested, use session_start() on index.php right at the top of you php page. Link to comment https://forums.phpfreaks.com/topic/30318-redirect-without-losing-variables-solved/#findComment-139536 Share on other sites More sharing options...
TEENFRONT Posted December 12, 2006 Share Posted December 12, 2006 Id also convert the session vars into an easier to use var like below. then you can use $wwidth etc, rather than the longer $_SESSION["window_width"]$wwidth = $_SESSION["window_width"];$wheight = $_SESSION["window_height"]; Link to comment https://forums.phpfreaks.com/topic/30318-redirect-without-losing-variables-solved/#findComment-139538 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.