Jump to content

Duplicate Session ID problem (PHP/MySQL)


brianbayer1

Recommended Posts

i'm getting a duplicate user_id error here. i wanted to assign a new session id everytime someone logs in. what am i doing wrong? here's the code:

 

<?php

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

if (strlen($username) <= 25 && strlen($password) <= 25) { 
	mysql_connect('localhost', 'user', 'password');
	mysql_select_db('users');
	$sql = "SELECT username, password FROM info WHERE username =
			'$username' AND password = password('$password');";
	$result = mysql_query($sql) or die(mysql_error());
	$newResult = mysql_fetch_array($result, MYSQL_ASSOC);
	if ($newResult['password'] = $password) {
		$_POST['logged'] = true;
		session_start();
		$_SESSION['name'] = session_id();
		$session_id = $_SESSION['name'];
		$_SESSION['username'] = $_POST['username'];
		$_SESSION['password'] = $_POST['password'];
		$sql = "UPDATE info SET user_id='$session_id' WHERE username='$username';";
		$result2 = mysql_query($sql) or die(mysql_error());
		mysql_close();
		header("Location: http://localhost/test/members/index.php");
	} else {
		$_POST['not_logged'] = true;
		header("Location: http://localhost/test/login.php");
	}
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.