GameYin Posted April 28, 2008 Share Posted April 28, 2008 <?php session_start(); include 'config.php'; $user = $_POST['username']; $pass = $_POST['password']; $query = mysql_query("SELECT * FROM Users WHERE Username = '$user' AND Password = '$pass' LIMIT 1") or die(mysql_error()); $row = mysql_fetch_array($query); if($name != "" && $pass != "" || mysql_num_rows($query) > 0 || $row['Activated'] > 0) { $_SESSION["status"] = "Logged"; $_SESSION['username'] = $user; $_SESSION['password'] = $pass; header("Location: index.php"); exit; } else { $_SESSION["status"] = "Not logged"; $_SESSION['username'] = Guest; echo "Something went wrong"; } ?> www.gameyin.com/login.php Enter these details Admini <-- User gameyin <--Pass It always enters the error message when you hit submit Quote Link to comment https://forums.phpfreaks.com/topic/103313-solved-if-statement-for-login-script-multiple-conditions/ Share on other sites More sharing options...
DarkWater Posted April 28, 2008 Share Posted April 28, 2008 $user = $_POST['username']; $pass = $_POST['password']; $query = mysql_query("SELECT * FROM Users WHERE Username = '$user' AND Password = '$pass' LIMIT 1") or die(mysql_error()); $row = mysql_fetch_array($query); if($user != "" && $pass != "" || mysql_num_rows($query) > 0 || $row['Activated'] > 0) { $_SESSION["status"] = "Logged"; $_SESSION['username'] = $user; $_SESSION['password'] = $pass; header("Location: index.php"); exit; } Stupid error, but you set $user = $_POST['username'], then you compare $name to "". Change the variable name like I did in the above code. Quote Link to comment https://forums.phpfreaks.com/topic/103313-solved-if-statement-for-login-script-multiple-conditions/#findComment-529126 Share on other sites More sharing options...
soycharliente Posted April 28, 2008 Share Posted April 28, 2008 Also, is Guest a global? Look where you're setting username to Guest. Quote Link to comment https://forums.phpfreaks.com/topic/103313-solved-if-statement-for-login-script-multiple-conditions/#findComment-529129 Share on other sites More sharing options...
GameYin Posted April 28, 2008 Author Share Posted April 28, 2008 Hmm, I was rewriting the variables, I figured that $user was better then $name. My bad. Also what about globals? I'm bad at those...Is it because I didn't enclose Guest with ""? I rewrote it with correct variable name and it sent me back to index.php. Can you write an if statement for my index.php to see if session variable is set? Or echo it? Quote Link to comment https://forums.phpfreaks.com/topic/103313-solved-if-statement-for-login-script-multiple-conditions/#findComment-529135 Share on other sites More sharing options...
revraz Posted April 28, 2008 Share Posted April 28, 2008 Yes Is it because I didn't enclose Guest with ""? Quote Link to comment https://forums.phpfreaks.com/topic/103313-solved-if-statement-for-login-script-multiple-conditions/#findComment-529159 Share on other sites More sharing options...
GameYin Posted April 29, 2008 Author Share Posted April 29, 2008 Allright. That was 1 of 2 things I noticed I did differently. Accidental lol. So how can I echo my session on index.php Quote Link to comment https://forums.phpfreaks.com/topic/103313-solved-if-statement-for-login-script-multiple-conditions/#findComment-529464 Share on other sites More sharing options...
GameYin Posted April 29, 2008 Author Share Posted April 29, 2008 Erm, anyone? Simple question. How can I echo my session var. Quote Link to comment https://forums.phpfreaks.com/topic/103313-solved-if-statement-for-login-script-multiple-conditions/#findComment-529770 Share on other sites More sharing options...
GameYin Posted April 29, 2008 Author Share Posted April 29, 2008 Help help help. Quote Link to comment https://forums.phpfreaks.com/topic/103313-solved-if-statement-for-login-script-multiple-conditions/#findComment-529798 Share on other sites More sharing options...
craygo Posted April 29, 2008 Share Posted April 29, 2008 echo $_SESSION['username']; same way you echo any other variable. Ray Quote Link to comment https://forums.phpfreaks.com/topic/103313-solved-if-statement-for-login-script-multiple-conditions/#findComment-529817 Share on other sites More sharing options...
GameYin Posted April 29, 2008 Author Share Posted April 29, 2008 I have the code in my index.php. I login but nothing is echoed. www.gameyin.com (Register, login then goto index.php) Something is wrong with my loginaction.php I guess? OR... loginaction.php <?php session_start(); include 'config.php'; $user = $_POST['username']; $pass = $_POST['password']; $query = mysql_query("SELECT * FROM Users WHERE Username = '$user' AND Password = '$pass' LIMIT 1") or die(mysql_error()); $row = mysql_fetch_array($query); if($user != "" && $pass != "" || mysql_num_rows($query) > 0 || $row['Activated'] > 0) { $_SESSION["status"] = "Logged"; $_SESSION['username'] = $user; $_SESSION['password'] = $pass; header("Location: index.php"); exit; } else { $_SESSION["status"] = "Not logged"; $_SESSION['username'] = Guest; echo "Something went wrong"; } ?> index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>DevPlooth.com | Forums | Arcade | Tutorials | Web Hosting</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="description" content="Find webmasters, web designers, SEO techs, web developers, designers PHP experts, html experts, javascript experts, css experts, SEO advice, marketing tips and resources. Our forum provides a way for people to find web help and support!" /> <meta name="keywords" content="webmaster forum, web design, web developers, developer forum, web forum, php experts, web marketing, seo experts, database experts, support forum, programming, html, css, javascript, mysql, sql, web" /> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <div class="body-container"> <div class="body-outer" id="body-outer"> <div class="body-header"> <div class="logo"> <a href="#">DevPlooth.com</a><br /> <small>Forums | Arcade | Tutorials | Web Hosting |</small> </div> <div class="tmenu"> <b><a class="add" href="index.php">Home</a></b> <a href="register.php">Register</a> <a href="login.php">Login</a> <a href="logout.php">Logout</a> <a href="usercp/index.php">UserCP</a> <a href="arcade/index.php">Arcade</a> <a href="tutorials/index.php">Tutorials</a> <a href="forums/index.php">Forums</a> <a href="webhosting/index.php">Web Hosting</a> </div> <div class="search"> <form action="search.php" method="get" style="display:inline;"> <div> <input type="text" name="search" class="input-search" value="Enter your Search Query" onblur="if(this.value=='') this.value='Enter your Search Query';" onfocus="if(this.value=='Enter your Search Query') this.value='';" /> <input type="image" src="images/search.gif" /></div> </form> </div> </div> </div> </div> <div class="navbar"> <small>Please browse our tutorials in many languages!</small> <br /> <table id="navbar"><tr><td>�<a href="tutorials/xhtml/index.html">(X)HTML</a></td></tr> <tr><td>�<a href="tutorials/css/index.html">CSS</a></td></tr> <tr><td>�<a href="tutorials/javascript/index.html">JavaScript</a></td></tr> <tr><td>�<a href="tutorials/php/index.html">PHP</a></td></tr> <tr><td>�<a href="tutorials/asp/index.html">ASP</a></td></tr> <tr><td>�<a href="tutorials/aspnet/index.html">ASP.NET</a></td></tr> <tr><td>�<a href="tutorials/coldfusion/index.html">ColdFusion</a></td></tr> <tr><td>�<a href="tutorials/mysql/index.html">MySQL</a></td></tr> <tr><td>�<a href="tutorials/apache/index.html">Apache</a></td></tr> <tr><td>�<a href="tutorials/dhtml/index.html">DHTML</a></td></tr> <tr><td>�<a href="tutorials/ajax/index.html">AJAX</a></td></tr> <tr><td>�<a href="tutorials/xml/index.html">XML</a></td></tr> <tr><td>�<a href="tutorials/xslt/index.html">XSLT</a></td></tr> <tr><td>�<a href="tutorials/actionscript/index.html">ActionScript</a></td></tr> <tr><td>�<a href="tutorials/vbscript/index.html">VBScript</a></td></tr> <tr><td>�<a href="tutorials/vb/index.html">VB</a></td></tr> <tr><td>�<a href="tutorials/python/index.html">Python</a></td></tr> <tr><td>�<a href="tutorials/rubyonrails/index.html">Ruby On Rails</a></td></tr> </table> </div> <?php echo $_SESSION['username']; ?> <div class="advertisement"> <p>Have A Look At Some Of Our Sponsors</p> <img src="images/ad1.gif" alt="Ads" /> <img src="images/ad2.gif" alt="Ads" /> <img src="images/ad3.gif" alt="Ads" /> <img src="images/ad4.gif" alt="Ads" /> <img src="images/ad5.jpg" alt="Ads" /> <img src="images/ad6.gif" alt="Ads" /><br /> <a href="advertise.php">Put Ad here</a> <a href="advertise.php">Put Ad here</a> <a href="advertise.php">Put Ad here</a> <a href="advertise.php">Put Ad here</a> <a href="advertise.php">Put Ad here</a> <a href="advertise.php">Put Ad here</a> </div> <div id="footer"> <p> <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Strict" height="25" width="70" /></a> © 2008-2009 DevPlooth.com. All rights reserved <a href="http://jigsaw.w3.org/css-validator/"> <img style="border:0;width:70px;height:25px" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /> </a> </p> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/103313-solved-if-statement-for-login-script-multiple-conditions/#findComment-529822 Share on other sites More sharing options...
craygo Posted April 29, 2008 Share Posted April 29, 2008 You have to start your session on index.php. FIRST THING! <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>DevPlooth.com | Forums | Arcade | Tutorials | Web Hosting</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="description" content="Find webmasters, web designers, SEO techs, web developers, designers PHP experts, html experts, javascript experts, css experts, SEO advice, marketing tips and resources. Our forum provides a way for people to find web help and support!" /> <meta name="keywords" content="webmaster forum, web design, web developers, developer forum, web forum, php experts, web marketing, seo experts, database experts, support forum, programming, html, css, javascript, mysql, sql, web" /> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> If you are using sessions, session_start() HAS to be the first thing on every page you write. Ray Quote Link to comment https://forums.phpfreaks.com/topic/103313-solved-if-statement-for-login-script-multiple-conditions/#findComment-529830 Share on other sites More sharing options...
GameYin Posted April 29, 2008 Author Share Posted April 29, 2008 I actually had that, I just didn't copy and paste high enough. Sorry! Quote Link to comment https://forums.phpfreaks.com/topic/103313-solved-if-statement-for-login-script-multiple-conditions/#findComment-529840 Share on other sites More sharing options...
GameYin Posted April 29, 2008 Author Share Posted April 29, 2008 Lol, I misspelled session_start();. I did sesion_start(); Woops. Yea that fixed it. Quote Link to comment https://forums.phpfreaks.com/topic/103313-solved-if-statement-for-login-script-multiple-conditions/#findComment-529853 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.