Jump to content

variable variable name...


aximbigfan

Recommended Posts

I have an app, and I want to create a var in $_SESSION that has a UID in it.

The UID part is already taken care of, I just need to figure out how to create a var with that UID in the name.

 

For example, I would liek to have a var with the name of...

 

$_SESSION['134354567634'] = "logged_in";

 

Chris

 

Looks like you just answered your own question.

 

When a user logs in with a correct username and password you return the uid from the database.  Then save the uid as a session variable.

 

<?php
// run query
$query = "SELECT `uid` FROM `users` WHERE `username` = '$username' AND `password` = '$password'";
$run = mysql_query($query);
$uid = mysql_result($run,0,"uid");
$_SESSION["$uid"] = "Logged In";
?>

 

I would like to say that this isn't typically the best way to detect which users are logged in.  From my experience, doing this would work better.

 

<?php
// run query
$query = "SELECT `uid` FROM `users` WHERE `username` = '$username' AND `password` = '$password'";
$run = mysql_query($query);
$uid = mysql_result($run,0,"uid");
$_SESSION['uid'] = $uid;
?>

Ok, thanks, I just didn't know that I could do it liek that.

 

Actually, the system is pretty much exactly the same as what you described. I vastly simplified it when I explained it. The only difference is in the form, and the fact that I'm using flat files (parse_ini_file). Haven't learned MySQL yet...

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.