1Yannick1 Posted September 9, 2009 Share Posted September 9, 2009 Hi, I have a little problem with my coding. It's a while since I used PHP but I wanted to try it again. I tried to make a simple login system with sessions. No databases just a simple POST-form where two entries (name and birth year) are stored in the session and displayed on the next page. So here is the problem: When I fill in the name and year in the form and click the submit-button I get an error on the next page (but the information is attached tot the session). If I access the site again I get the name and year displayed. But How do I get it displayed without getting an error first? By the way this is the error: Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0 So on the first page is a HTML-code with the POST-form: <html> <head> <title>::Welcome!::</title> </head> <body> Welcome!<br> Please enter your name and birthyear below.<br> <form name="form1" method="post" action="gotname.php"> Name:<input name="name" type="text" id="name"><br> Birthyear:<input name="year" type="text" id="year"><br> <input type="submit" name="submit" value="Submit!"> </form><br> <a href="linkpage.php">link</a><br> <?php $date=date("d-m-Y"); echo $date; ?> </body> </html> And on the second page the code (where the form-entries are posted): <?php session_start(); if (isset($_POST['submit'])) { if ($_POST['name'] == "") { $nameerror = "Fill in a name!"; } if ($_POST['year'] == "") { $yearerror = "Fill in a year!"; } if (!isset($nameerror) && !isset($yearerror)) { $name=$_POST['name']; $year=$_POST['year']; session_register("name"); session_register("year"); } } ?> <html> <head> <title>::Welcome!::</title> </head> <body> <?php if (isset($_POST['submit'])) { if (isset($name) && isset($year)){ echo "Name:".$_SESSION["name"]."<br>"; echo "Year:".$_SESSION["year"]; } else{ echo $nameerror; echo $yearerror; } } else{ echo "You have to fill in the form first!"; } ?> <br> <br> <a href="index.php">Go back!</a><br> <br> <?php $date=date("d-m-Y"); echo $date; ?> </body> </html> I know it's not a very difficult code but I can't figure out what to do to fix it. I hope someone here can help me. Link to comment https://forums.phpfreaks.com/topic/173648-session-first-time-error-and-works-the-second-time/ Share on other sites More sharing options...
Jibberish Posted September 9, 2009 Share Posted September 9, 2009 try using $_SESSION['year'] = $year; $_SESSION['name'] = $name; instead of session_register("name"); session_register("year"); session_register has been depricated now, and according to PHP.net as of PHP 6.0.0 it has been removed Link to comment https://forums.phpfreaks.com/topic/173648-session-first-time-error-and-works-the-second-time/#findComment-915351 Share on other sites More sharing options...
TeNDoLLA Posted September 9, 2009 Share Posted September 9, 2009 Please use code tags. Also could be good to post only the relevant code to make it shorter. Link to comment https://forums.phpfreaks.com/topic/173648-session-first-time-error-and-works-the-second-time/#findComment-915352 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.