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

 

Link to comment
Share on other sites

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;
?>

Link to comment
Share on other sites

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

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.