Jump to content

Session depending on logged in user


thereaper87

Recommended Posts

This will be a little difficult to explain, but keep with me.

On the profile.php page. It starts a new session.

// Connect to MySQL...
$conn = mysql_connect($hostname, $username, $password)      or die("Connecting to MySQL failed");  
mysql_select_db($database, $conn)     or die("Selecting MySQL database failed"); 

// Run our query, see if session username exists in session field...
$sql="select username,email from user where username='{$_SESSION['user']}' limit 1";
$result=mysql_query($sql,$conn);
// Parse our results into $data (as an associative array)...
$data=mysql_fetch_assoc($result);

// If one row was found in the result set, username exists...
if (mysql_num_rows($result)==1) {
$_SESSION['sellername'] = $data['username'];

So what I am hoping that is doing, is the session named "sellername" is stored with the variable of the logged in user. In this example "testuser".

Now the page updates.php will have an id attached to like so: updates.php?id=13. Which will have info only available for testuser's eyes. On the page it does this.

// Connect to MySQL...
$conn = mysql_connect($hostname, $username, $password)      or die("Connecting to MySQL failed");  
mysql_select_db($database, $conn)     or die("Selecting MySQL database failed");
// Run our query, see if session username exists in session field...
$sql="select username from user where username='{$_SESSION['user']}' limit 1";
$result=mysql_query($sql,$conn);
// Parse our results into $data (as an associative array)...
$data=mysql_fetch_assoc($result);

// If one row was found in the result set, username exists...
if (mysql_num_rows($result)==1) {
$query='select seller from listings where seller = "'.$data['username'].'"';
$queryresult=mysql_query($query,$conn);
while($info = mysql_fetch_assoc($queryresult)){
if ( $_SESSION['sellername'] == $info['seller'] ){

The if statement should process: "If the session variable for 'sellername' equals the database entry 'seller' then display the rest of the page."

However, no matter what user is logged, it will display the page. Any ideas?

 

Link to comment
https://forums.phpfreaks.com/topic/210585-session-depending-on-logged-in-user/
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.