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
https://forums.phpfreaks.com/topic/102362-duplicate-session-id-problem-phpmysql/
Share on other sites

Archived

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

×
×
  • 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.