View Full Version : Login help

06-28-2007, 12:06 AM
Hey everyone,
I have had trouble with my login system. the problem is the page keeps refreshing. Here is the code.


if (ISSET($_POST['sublogin']))
// Recreation of variables for later encryption uses the $_POST will be replaced with the decrypted source
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$cryptpassword = md5($password);
$url = '/cp.php?user=$_SESSION[username]';
//Connects to DB
$table = "users";

$sql="SELECT username, userID FROM $table WHERE username='$username' and password='$cryptpassword'";
$result = mysql_query($sql)or die(mysql_error());

// If result matched $myusername and $mypassword, table row must be 1 row
if(mysql_num_rows($result) > 0)
// Registers sesions and redirect to file "login_success.php"

$storage = mysql_fetch_assoc($result);

//Sessions here
$_SESSION['username'] = $storage['username'];
$_SESSION['userid'] = $storage['userID'];

header("location: $url");
echo "Wrong Username or Password";

function displayLogin(){
global $logged_in;
echo "Logged In<br />";
echo "Welcome <b>$_SESSION[username]</b>, you are logged in. <br><br>"
."<a href=\"cp.php?user=$_SESSION[username]\">My Account</a><br /> ";
echo "<a href=\"logout.php\">Logout</a>";

<form action="" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td></tr><tr><td><input type="text" name="username" size="15" maxlength="30"/></td></tr>
<tr><td>Password:</td></tr><tr><td><input type="password" name="password" size="15" maxlength="30"></td></tr><tr><td>
<input type="submit" name="sublogin" value="Login" style="font-size: 8pt; color: #000000; word-spacing: 0; margin-top: 0; margin-bottom: 0" /></td></tr>

* This is the cool part: the user has requested that we remember that
* he's logged in, so we set two cookies. One to hold his username,
* and one to hold his md5 encrypted password. We set them both to
* expire in 100 days. Now, next time he comes to our site, we will
* log him in automatically.
setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/");
setcookie("cookid", $_SESSION['userid'], time()+60*60*24*100, "/");

/* Quick self-redirect to avoid resending data on refresh */
echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";

/* Sets the value of the logged_in variable, which can be used in your code */
$logged_in = checkLogin();


The website is at both, infinitevortex.ulmb.com/login.php and taizkul.prohosts.org. They ue the same script...but i made two for testing purposes
Thank you for your time

06-28-2007, 01:36 AM
I'm just taking a shot in the dark... But I think you might want to try starting your session at the very top of you page.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum