Jump to content

All Of A Sudden Stopped Working?


kirbyweb

Recommended Posts

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

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

You have to call session_start before any output. This won't work:

  <?phpsession_start();

Link to comment
Share on other sites

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

<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

<?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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...