kirbyweb Posted December 4, 2009 Share Posted December 4, 2009 OK when a user logs into my site, it says welcome there username.All of a sudden it stopped working, it says it the first page they view but if they click on a link then it goes away, it has all the other member stuff, here is the code: <font color='white'><?phpsession_start();if ($_POST['login']) {if (isset($_POST['username']) and isset($_POST['password'])) { $connect = mysql_connect('____', '_____', '_______') or die('Couldn\'t connect!'); mysql_select_db('__________') or die('Couldn\'t find db'); $username = mysql_real_escape_string($_POST['username']); $password = md5($_POST['password']); $query = mysql_query("SELECT * FROM ___ WHERE username = '$username' AND password = '$password'"); $row = mysql_fetch_assoc($query); { $activated = $row['activated'];} if ($activated=='0') { die("Your account is not yet activated. Please check your email."); exit();} if (mysql_num_rows($query) == 1) { echo 'Welcome ' .$row["username"] .'.'; $_SESSION['username']=$username; } else echo 'Incorrect username/password!';} else die('User/pass not POSTed!');}?></font> Does anyone know why?Here log into this site with this username + passwordkingdomsarcade.byethost5.comusername: test222password: test222Can anyone help? Link to comment Share on other sites More sharing options...
kirbyweb Posted December 4, 2009 Author Share Posted December 4, 2009 This file is on all files. Link to comment Share on other sites More sharing options...
kirbyweb Posted December 5, 2009 Author Share Posted December 5, 2009 Does anyone know why? Link to comment Share on other sites More sharing options...
jlhaslip Posted December 5, 2009 Share Posted December 5, 2009 remove the font tag before the session_start Link to comment Share on other sites More sharing options...
kirbyweb Posted December 5, 2009 Author Share Posted December 5, 2009 Nope. Link to comment Share on other sites More sharing options...
kirbyweb Posted December 5, 2009 Author Share Posted December 5, 2009 Ok here is the page that is including the login file: <?php include ('login.php'); if (empty($_SESSION['username'])){ ?><form method='POST'><span style='color: white;'>Username</span><br /><input type='text' style='border: none;' name='username'><br /><span style='color: white;'>Password</span><br /><input type='password' style='border: none;' name='password' /><br /><br /><input type='submit' name='login' style='border: none;' value='Log in' /></form><?php } else {?><br /><br /><a href='logout.php'>Log Out</a><br /><br /><a href='changepassword.php'>Change password</a><?php } ?><br /><br /><a href='register.php'>Register?</a> Or most of it anyways.But that file is included on all the pages, the login file is at the top of this thread.Anyways when I log in it only displays the username for one page, then it goes away even if I click back or what ever. Link to comment Share on other sites More sharing options...
Synook Posted December 5, 2009 Share Posted December 5, 2009 You have to call session_start before any output. This won't work: <?phpsession_start(); Link to comment Share on other sites More sharing options...
thescientist Posted December 5, 2009 Share Posted December 5, 2009 so would he get rid of the font tag at the beginning? Link to comment Share on other sites More sharing options...
jlhaslip Posted December 5, 2009 Share Posted December 5, 2009 yes, because as soon as the font tag or blank spaces are sent to the Browser, headers get sent. Link to comment Share on other sites More sharing options...
kirbyweb Posted December 5, 2009 Author Share Posted December 5, 2009 So what do I do? Link to comment Share on other sites More sharing options...
kirbyweb Posted December 5, 2009 Author Share Posted December 5, 2009 I think it has something to do with the query? Link to comment Share on other sites More sharing options...
kirbyweb Posted December 5, 2009 Author Share Posted December 5, 2009 Or with the button being pressed? Cannot figure out for sure though. Link to comment Share on other sites More sharing options...
phpnoob Posted December 5, 2009 Share Posted December 5, 2009 Or with the button being pressed? Cannot figure out for sure though.i cant understand,what its your problemLogin problem? Link to comment Share on other sites More sharing options...
kirbyweb Posted December 5, 2009 Author Share Posted December 5, 2009 When I log in it displays the username for one! page, then it goes away. Link to comment Share on other sites More sharing options...
phpnoob Posted December 5, 2009 Share Posted December 5, 2009 When I log in it displays the username for one! page, then it goes away.Add this cod to echo $_SESSION ['username']this cod its false $row["username"]Why?because this is just a POST data poccess, if you send a data to mysql you get the user name, but if you loged in, and refresh the page, this code not give you anything, because you not send data to mysql.I hope i understand this Link to comment Share on other sites More sharing options...
kirbyweb Posted December 5, 2009 Author Share Posted December 5, 2009 Nope. That did not work. Link to comment Share on other sites More sharing options...
phpnoob Posted December 5, 2009 Share Posted December 5, 2009 Nope. That did not work.what not working the $_SESSION['username']? impossible!!! Link to comment Share on other sites More sharing options...
kirbyweb Posted December 5, 2009 Author Share Posted December 5, 2009 It just does the same thing as before, nothing different. Link to comment Share on other sites More sharing options...
kirbyweb Posted December 5, 2009 Author Share Posted December 5, 2009 <font color='white'><?phpsession_start();if ($_POST['login']) {if (isset($_POST['username']) and isset($_POST['password'])) { $connect = mysql_connect('_____', '______', '____') or die('Couldn\'t connect!'); mysql_select_db('_________') or die('Couldn\'t find db'); $username = mysql_real_escape_string($_POST['username']); $password = md5($_POST['password']); $query = mysql_query("SELECT * FROM ____ WHERE username = '$username' AND password = '$password'"); $row = mysql_fetch_assoc($query); { $activated = $row['activated'];} if ($activated=='0') { die("Your account is not yet activated. Please check your email."); exit();} if (mysql_num_rows($query) == 1) { echo $_SESSION['username']; $_SESSION['username']=$username; } else echo 'Incorrect username/password!';} else die('User/pass not POSTed!');}?></font> Thats the login file.Here is the file that is on all pages, or most of it: <?phpinclude ('page file.php');?><---HTML CODE HERE---><?phpinclude ('login.php'); if(empty($_SESSION['username'])) { ?><form method='POST'><span style='color: white;'>Username</span><br /><input type='text' style='border: none;' name='username'><br /><span style='color: white;'>Password</span><br /><input type='password' style='border: none;' name='password' /><br /><br /><input type='submit' name='login' style='border: none;' value='Log in' /></form><?php } else {?><br /><br /><a href='logout.php'>Log Out</a><br /><br /><a href='changepassword.php'>Change password</a><?php } ?><br /><br /><a href='register.php'>Register?</a></table> Link to comment Share on other sites More sharing options...
phpnoob Posted December 5, 2009 Share Posted December 5, 2009 <?phpsession_start();if ($_POST['login']) {if (isset($_POST['username']) and isset($_POST['password'])) {$connect = mysql_connect('_____', '______', '____') or die('Couldn\'t connect!');mysql_select_db('_________') or die('Couldn\'t find db');$username = mysql_real_escape_string($_POST['username']);$password = md5($_POST['password']);$query = mysql_query("SELECT * FROM ____ WHERE username = '$username' AND password = '$password'");$row = mysql_fetch_assoc($query);$activated = $row['activated'];if ($activated=='1'){ if (mysql_num_rows($query) == 1) {echo $_SESSION['username'];} else {echo 'Incorrect username/password!';}}else{echo 'Your account is not yet activated. Please check your email. ';}}}?>Try this, but i think its not good because i don't know what you are want to checkit in the activated column Link to comment Share on other sites More sharing options...
kirbyweb Posted December 5, 2009 Author Share Posted December 5, 2009 Does not work, does anyone know how to fix this!!!! Link to comment Share on other sites More sharing options...
phpnoob Posted December 5, 2009 Share Posted December 5, 2009 lol, i check my login php, " ob_start();"i dont see that code on your php file Link to comment Share on other sites More sharing options...
kirbyweb Posted December 5, 2009 Author Share Posted December 5, 2009 What about it, all of a sudden the code stopped working for no reason, and now when I log in, it logs me out, and the code is the same, I copied the code on the first page of this site???Something is up. Link to comment Share on other sites More sharing options...
phpnoob Posted December 5, 2009 Share Posted December 5, 2009 last tryThis is my login.php try it, i modified to your column name, if it works i put it the last line "if ($activated=='1'){ "<? session_start(); ob_start();?><?if ($_SESSION['loggedin']!== true){if (isset($_POST['login'])){$username = addslashes($_POST['username']);$pass = md5($_POST['password']);$sql = "SELECT * FROM _____ ";$sql.= "WHERE (username='".$username."'";$sql.= " AND password='".$pass."')";$query = mysql_query($sql);if (mysql_num_rows($query) !== 0){$_SESSION['username'] = addslashes($_POST['username']);$_SESSION['loggedin'] = true;header("Location: ".$_SERVER['PHP_SELF']);setcookie("loggedin","username",time()+7200);}else{echo "Error nick/pass";}}echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\"> <input type=\"text\" value=\"username\" onBlur=\"if(this.value=='') this.value='username';\" onFocus=\"if(this.value=='username') this.value='';\" name=\"username\" size=\"15\"><br> <input type=\"password\" value=\"123456789012345\" onBlur=\"if(this.value=='') this.value='123456789012345';\" onFocus=\"if(this.value=='123456789012345') this.value='';\" name=\"password\" size=\"15\"> <input type=\"submit\" name=\"login\" value=\"OK\"></form><br><br><br><a href=\"register.php\">Register?</a> | <a href=\"changepassword.php\">Change password</a>";}else {echo 'Helo '.$_SESSION['username'].'<br><br><br><br><br><br><a href="logout.php">Log Out</a>';}?> Link to comment Share on other sites More sharing options...
kirbyweb Posted December 5, 2009 Author Share Posted December 5, 2009 No its not modified to my version, I will just wait till one of the advanced php programmers comes on. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.