cliftonbazaar Posted April 10, 2009 Share Posted April 10, 2009 Brand new to PHP (just switched from ASP) so please be patient as I convert all my pages I have 2 pages - register.php and adduser.php On the first page the user is to fill out all their information (name and email mostly), the second page checks the information to make sure it is 'valid' before it adds the information to the database, the first check is to make sure they have entered and email address (my access database was full of blank entries :-\ ). The code I tried for register.php is <html> <?PHP Session_start(); IF (!empty($_Session["error"])) echo $_Session["error"]; ?> <head> //Rest of the code Code for adduser.php - <?PHP IF ($_POST["email"] == "") { header('Location:http://www.cliftonbazaar.com/register.php'); $_Session['error'] = "You have not stipulated an email address."; die(); } ?> //THERE IS NO OTHER CODE FOR THIS PAGE AT THIS TIME This seems to redirect the user succesfully back to the register page if there is no email addy but the error message is not displayed. Link to comment https://forums.phpfreaks.com/topic/153412-solved-setting-up-session-variable-and-page-redirection/ Share on other sites More sharing options...
xtopolis Posted April 10, 2009 Share Posted April 10, 2009 You should be getting header warnings/errors. In register.php, you have output before session_start() in the form of "<html>" which is not allowed. register.php <?php ini_set('display_errors', 1);//use these while debugging error_reporting(E_ALL);//use these while debugging session_start(); if(!empty($_SESSION['error'])){ echo $_SESSION['error']; } ?> <html> <head> ... @mrMarcus - it only has to be present before any SESSION variable are accessed, and before anything is output to the page (when the server finishes processing and begins to send it back to the browser). Link to comment https://forums.phpfreaks.com/topic/153412-solved-setting-up-session-variable-and-page-redirection/#findComment-806000 Share on other sites More sharing options...
mrMarcus Posted April 10, 2009 Share Posted April 10, 2009 you must have session_start(); at the top of any page using $_SESSION's .. whether you're accessing them or declaring them. Link to comment https://forums.phpfreaks.com/topic/153412-solved-setting-up-session-variable-and-page-redirection/#findComment-806001 Share on other sites More sharing options...
cliftonbazaar Posted April 10, 2009 Author Share Posted April 10, 2009 Thank you both for your replies, I'm currently learning by reading a book so I have a long way to go ini_set('display_errors', 1);//use these while debugging error_reporting(E_ALL);//use these while debugging Didn't read anything about these lines but now I'll be using them full time, makes life a 100 times easier Also learnt the hard way that SESSION needs to be all upper caps Link to comment https://forums.phpfreaks.com/topic/153412-solved-setting-up-session-variable-and-page-redirection/#findComment-806016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.