deansaddigh Posted March 9, 2009 Share Posted March 9, 2009 Hi i am new to php and am having problems with creating sessions. My login works but when i include session code at the top of the page it will not let the user go to the required page in this case it is studenthome.php. I think that it is not populating the php session variable. Logincheck.php <?php //Use the connect script to connect to CIS School database require "connectstudent.php"; //Use the student data to connect to the database $dbuser = $_GET["user"]; $dbpass = $_GET["password"]; $dbhost = 'localhost'; $dbname = 'CISSchool'; //Build the query checking the username and passowrd entered is correct $query = "select * from student where StudentUsername ='".$dbuser."' and StudentPassword = '".$dbpass."'" ; $result = mysql_query($query, $conn) or die ("Unable to perform query. <br/> $query <br/>" . mysql_error()); //Retrieve the data that is stored in the array $row= mysql_fetch_array($result); //If there is a match then take them to the student page if ($row != null) { $_SESSION["user"] = $row['StudentUsername']; header("Location: studenthome.php"); exit(); } //Else display error message and navigate to homepage else { //Pass this message to the index screen to let the user know they have incorrect login details $message = 'Invalid user name or password, please try again'; header("Location: index.php? message=$message"); exit(); } ?> studenthome.php <?php session_start(); if (isset($_SESSION['user']) == false) { header("Location:index.php"); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link href="cis.css" rel="stylesheet" type="text/css" media="screen" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>cisukschool.co.uk: Great value learning</title> </head> <!--Open body--> <body> <!--Open container--> <div id="container"> <!--Open header--> <div id="topheader"> <?php $_SESSION['user'];?> <!--Open form, used to logout student--> <div id="formlogin"> <!--Form code--> <form name="logout" id="logout" method="post" action="logout.php"> <label> <input type="submit" name="submit" value="Log out" tabindex="1" class="submitbutton" /> </label> <!--Close form code--> </form> <!--Close form--> </div> <!--Close header--> -</div> <!--Open logo--> <div id="logo"> <!--Close logo--> </div> <!--Open left column--> <div id="leftcolumn"> <h1> Welcome</h1> <h1> Info</h1> <!--Close left column--> </div> <!--Open right column--> <div id="rightcolumn"> <!--Close right column--> </div> <!--Open footer--> <div id="footer"> <p align="center"> CIS School of English STUDENT</p> <!--Close footer--> </div> <!--Close the container--> </div> <!--Close body--> </body> </html> Thanks in advance Link to comment https://forums.phpfreaks.com/topic/148586-solved-sessions/ Share on other sites More sharing options...
WolfRage Posted March 9, 2009 Share Posted March 9, 2009 logincheck.php is missing session_start(); . Link to comment https://forums.phpfreaks.com/topic/148586-solved-sessions/#findComment-780253 Share on other sites More sharing options...
deansaddigh Posted March 9, 2009 Author Share Posted March 9, 2009 Thank you so much like i said i am new to php Link to comment https://forums.phpfreaks.com/topic/148586-solved-sessions/#findComment-780263 Share on other sites More sharing options...
WolfRage Posted March 9, 2009 Share Posted March 9, 2009 No problem please mark it solved, thanks. Link to comment https://forums.phpfreaks.com/topic/148586-solved-sessions/#findComment-780265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.