Stalingrad Posted July 28, 2008 Share Posted July 28, 2008 Hello. I've created a simple login and when I login it's not settingf the session. When I go to the home page it displays the content that is displayed when you're not logged in. Here's the login: <?php session_start(); include("config.php"); if($_SESSION['username'] != "") { echo "<div id=\"b\">$b</div><div id=\"n\">$nav</div><div id=\"c\"><img src=images/layout/login.jpg><br><br>Error! You are already Logged In.</div><div id=\"i\">$info</div>"; } if($_SESSION['username'] == "") { $submit = $_POST['submit']; $lusername = $_POST['username']; $lpassword = $_POST['password']; echo "<div id=\"b\">$b</div><div id=\"n\">$nav1</div></div><div id=\"i\">$info</div><div id=\"c\"><img src=images/layout/login.jpg><br><br>"; if(!isset($submit)) { ?><html><form action="<?php echo "$PHP_SELF" ?>" method="POST">Username: <input type="text" name="username" maxlength="16"><br><br>Password: <input type="password" name="password" maxlength="16"><br><br><br><input type="submit" name="submit" value="Login"></form></html><?php } if(isset($submit)) { $cq = mysql_query("SELECT * username FROM users WHERE username='$lusername' AND password='$lpassword'"); $c = @mysql_num_rows($cq); if($c == "0") { ?> <html><font color=red>Error! Invalid Username/Password Combination.</font><br><br><form action="<?php echo "$PHP_SELF" ?>" method="POST">Username: <input type="text" name="username" maxlength="16"><br><br>Password: <input type="password" name="password" maxlength="16"><br><br><br><input type="submit" name="submit" value="Login"></form></html><?php } if($c == "1") { $_SESSION['username'] = $lusername; $_SESSION['password'] = $lpassword; echo "You are now Logged in.<br><br>Click <a href=index.php>Here</a> to Continue."; } } } ?> And here's the index page: <?php session_start(); include("config.php"); if($_SESSION['username'] != "") { echo "<div id=\"b\">$b</div><div id=\"n\">$nav1</div><div id=\"c\">Welcome to Rock Land.</div><div id=\"i\"></div>"; } if($_SESSION['username'] == "") { echo "<div id=\"b\">$b</div><div id=\"n\">$nav</div><div id=\"c\">Welcome to Rock Land.</div><div id=\"i\">$info</div>"; } ?> I'm trying to make it so that when I login it creates the session so when I go to the index page it displays the content that gets displayed when you're logged in. Any help is greatly appreciated, please and thank you in advance! =] Link to comment https://forums.phpfreaks.com/topic/117017-php-session-not-working/ Share on other sites More sharing options...
MatthewJ Posted July 28, 2008 Share Posted July 28, 2008 First guess would be that the result of your query is not 1 Try echoing out that variable prior to that check and see if it is what it is supposed to be. Link to comment https://forums.phpfreaks.com/topic/117017-php-session-not-working/#findComment-601923 Share on other sites More sharing options...
PFMaBiSmAd Posted July 28, 2008 Share Posted July 28, 2008 If the first page indicates you did get logged in, add the following two lines after the first opening <?php tag on both pages - ini_set ("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/117017-php-session-not-working/#findComment-602007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.