phpparty Posted April 26, 2009 Share Posted April 26, 2009 I am fairly new to php and I am having some problems figuring out what I am doing wrong for a simple login I am doing. There is a login form which calls this page: <?php session_start(); session_register("user"); $username = $_POST['username']; $password = $_POST['password']; require_once("connect.php"); $querystring = "SELECT * FROM tbl_users WHERE user_username='".$username."' AND user_password='".$password."'"; $loginresult = mysql_query($querystring); $howmany = mysql_num_rows($loginresult); if($howmany == 1) { $_SESSION['user'] = "yes"; header("Location: cms.php"); }else{ header("Location: login.php"); } ?> This form does work I believe because if I enter a valid username and password I am taken to the "cms.php" page, and if the username or password is wrong I am taken to the login page again. The problems arise when I start trying to restrict the actions of the php depending on the user being logged in or not. This code, despite the user being logged in or not, while always return nothing: if(isset($_SESSION['user'])) { require_once("connect.php"); $portstring = "SELECT * FROM tbl_portfolio ORDER BY portfolio_id ASC"; $newsstring = "SELECT * FROM tbl_news ORDER BY news_id ASC"; $portinfo = mysql_query($portstring); $newsinfo = mysql_query($newsstring); }else{ } Any help that can be provided would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/155720-_session-problems/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 26, 2009 Share Posted April 26, 2009 Remove this line of code - session_register("user"); In the second piece of code, where is the session_start(); statement that would allow $_SESSION['user'] to exist on the page? Link to comment https://forums.phpfreaks.com/topic/155720-_session-problems/#findComment-819675 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.