aximbigfan Posted March 3, 2008 Share Posted March 3, 2008 Hi! I need to add a string of chars to a variable name. I assume IU cannot just do $_SESSION['{$uid}'} = "something_or_other"; How can I do that? Chris Quote Link to comment Share on other sites More sharing options...
p2grace Posted March 3, 2008 Share Posted March 3, 2008 What exactly do you need to do? Are you trying to add char to the session variable name, or to the content being saved in the variable declared? Quote Link to comment Share on other sites More sharing options...
aximbigfan Posted March 3, 2008 Author Share Posted March 3, 2008 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 Quote Link to comment Share on other sites More sharing options...
p2grace Posted March 3, 2008 Share Posted March 3, 2008 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; ?> Quote Link to comment Share on other sites More sharing options...
aximbigfan Posted March 3, 2008 Author Share Posted March 3, 2008 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... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.