ccravens Posted February 20, 2007 Share Posted February 20, 2007 Hello, I am having issues (and have had for some time) about redirecting while maintaining session variables. I am trying to redirect the user back to the registration page after failing my validation script. This is the page after a user hits the "Register" button to submit their information. My code would look something like this: <?php session_start(); if(!session_is_registered("errors")) { session_register("errors"); } $errors = array(); if(empty($somefield)) $errors['somefield'] = "Please enter the information"; if(count($errors)) { header("Location: http://my-url.com/Register.php"); exit(); } and when I try to access $errors['somefield'] within Register.php, it is empty. Register.php does have a session_start() call at the top. Thank you so much for your help! I appreciate any input into this issue. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 20, 2007 Share Posted February 20, 2007 You never store $errors into the session. Don't use session_register, just do $_SESSION['errors'] = $errors; after you have assigned values to errors. Quote Link to comment Share on other sites More sharing options...
ccravens Posted February 20, 2007 Author Share Posted February 20, 2007 Thank you for the help. The method I used is an example from an old book (2002) that I guess is outdated. The code works when I store the session variable firstname. For example: $_SESSION['firstname'] = "Please insert your first name"; However, am I not able to store an array into a session variable? For example: $errors['firstname'] = "Please insert your first name"; $_SESSOION['errors'] = $errors; Thank you! :-) Chad Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 20, 2007 Share Posted February 20, 2007 you spelt $_SESSION wrong. its $_SESSION not $_SESSOION but maybe you wrote that just then. you should be able to. example: <?php session_start(); $_SESSION['array_variable'] = array("Foo" => "Bar"); echo $_SESSION['array_variable']['Foo']; ?> The above will echo Bar. it works. tested. Quote Link to comment Share on other sites More sharing options...
ccravens Posted February 20, 2007 Author Share Posted February 20, 2007 Fantastic! Thank you very much for the help! Quote Link to comment 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.