Jump to content

Redirect without losing variables? [SOLVED]


monkey_05_06

Recommended Posts

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

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?
<?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.