Jump to content


login system transfering sessions not working

  • Please log in to reply
2 replies to this topic

#1 cameeob2003

  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 04 July 2006 - 09:54 PM

I am trying to allow my users to login to the site 1 time and then not have to login again until they have closed the window. I am using the following script wich I found on this site as a tutorial and have modified to authenticate my users:



header("Cache-control: private");

$user = $_POST['username'];
$pass = $_POST['password'];


// Check to see if the user exists.

$sql_user_check = "SELECT username FROM users WHERE username='$user'";
$result_name_check = mysql_query($sql_user_check) or die(mysql_error());
$usersfound = mysql_num_rows($result_name_check) or die(mysql_error());

// If the user is not found note that and end.
if($usersfound < 1){
	$error = "User ".$user." was not found in the database.";

		$user = $_POST['username'];
		$pass = md5($_POST['password']);
		$sql = "select * from users where `username` = '$user'";
		$result = mysql_query($sql);
		while ($text = mysql_fetch_array($result)) {
			$id = $text['id'];
			$password = $text['encrytpass'];
			$access = $text['access'];
		if ($pass == $password) {
			$error = "Wrong Username / Password <a href=\"?act=login\">Back</a>";
	// If the passwords do match, let in and go to the session variables.
		$_SESSION['userid'] = $text['userid'];
		$_SESSION['first_name'] = $text['first_name'];
		$_SESSION['last_name'] = $text['last_name'];
		$_SESSION['username'] = $text['username'];
		$_SESSION['password'] = $text['password'];
		$_SESSION['encryptpass'] = $text['encryptpass'];
		$_SESSION['email'] = $text['email'];
		$_SESSION['location'] = $text['location'];
		$_SESSION['steamid'] = $text['steamid'];
		$_SESSION['handle'] = $text['handle'];
		$_SESSION['bio'] = $text['bio'];
		$_SESSION['photo'] = $text['photo'];
		$_SESSION['team_name'] = $text['team_name'];
		$_SESSION['team_tag'] = $text['team_tag'];
		$_SESSION['access'] = $text['access'];
		$_SESSION['webs'] = $text['webs'];
		$_SESSION['priv_message'] = $text['priv_message'];

		echo $error;
		header("Location: index2.php");
		echo "<html><head><title>Welcome Back</title></head>Welcome back ". $_SESSION['username'] .".<a href=index2.php>Click here</a> to proceed."; 

here is the code I am using on index2.php to display information if the user is logged in:

<?php session_start();
	echo "You are logged in as:". $_SESSION['username'] ."<br/><br/>";
	echo "<font id=UserPanelText />You are not logged in.<br/><br/>";
	$newpms = $_SESSION['priv_messages'];
	if($newpms > "0"){
		echo "<a href=?page=newpmessage=$id>Unread Messages</a> (". $newpms .")<br/>";
		echo "<font id=UserPanelText /><a href=?page=pmessages=$id>Mailbox</a><br/><font id=UserPanelText /><a href=?page=user_panel>User Panel</a><br/>";
<div style="position: absolute; top: 225; left: 780;">
$sql = "SELECT * FROM `matches` order by `id` DESC LIMIT 0,3";
									  $result    = mysql_query($sql) or die(mysql_error());
									  $num     = mysql_num_rows($result);
									  while ($text = mysql_Fetch_array($result)) {
											$id = $row['id'];
											$team1 = $row['home_team'];
											$team2 = $row['away_team'];
											$score1 = $row['score_one'];
											$score2 = $row['score_two'];
											$sql2 = "SELECT $id FROM `matches` WHERE `id`='$id'order by `id` DESC LIMIT 0,3";
											$result2    = mysql_query($sql2) or die(mysql_error());
											$num2     = mysql_num_rows($result2);
											echo '
										<tr><td> $id </td><td height="18" width=35 valign="bottom" align="left"><font id=ctext />n2p <font id=dash />vs<font id=ttext /> $team2 </td><td width="34" height=18 align="right" valign="bottom"><font id=ctext /> $score1 <font id=dash />-<font id=ttext /> $score2 </td></tr>';

I am getting the not logged in message even though I beleive I have set the users sessions correctly. I have tried everything I can in my limited knowledge of php and also have searched google with no results.

here is an example of what is happening.
user: test
pass: test

#2 trq

  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 July 2006 - 10:23 PM

Your code makes little sense. Where do you define $text if the login is successfull?

#3 cameeob2003

  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 04 July 2006 - 11:36 PM

I got help from a friend :P and yes code was very bad had alot of revision to do to it.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users