xcandiottix Posted May 27, 2010 Share Posted May 27, 2010 but I guess it's time to learn how to do it. I need to pull the results from a column in my db and use it as a key to identify 2 other items in that row. Here's what I've written so far but it's not working so well. connect to database mysql_select_db("dbname", $con); $data = mysql_query("SELECT * FROM dbname") or die(mysql_error()); $rows = mysql_num_rows($data); while($info = mysql_fetch_array($data)) { $usernames = $info['db_Username']; } foreach ($usernames as $user => $pass) { if ( md5 ( $user . $password . $row['db_Id']. $_SERVER['REMOTE_ADDR'] ) == $_COOKIE['login'] ) { echo "you're already logged in"; } } What Im trying to accomplish is this; I have a cookie that has stored the users username, password, database id, and IP address. I have hashed it with md5. I know want to use the cookie to see if the cookie is still valid. To do this I am trying to say "For each username in the database get its corresponding password and id #. Then md5 it along with the users IP address... if a match is found to the users cookie then the user is logged in. If not, send the user to a log on page". Any help is appreciated =) Link to comment https://forums.phpfreaks.com/topic/203048-ive-been-dancing-around-this/ Share on other sites More sharing options...
xcandiottix Posted May 27, 2010 Author Share Posted May 27, 2010 Getting Closer <?php if (isset($_COOKIE['settings']) ) { $con = mysql_connect("DB","UN","PW"); mysql_select_db("rmvusers", $con); $data = mysql_query("SELECT * FROM DB") or die(mysql_error()); $rows = mysql_num_rows($data); while($info = mysql_fetch_array($data)){ $uns = $info['db_Username']; $pws = $info['db_Pass']; if(md5($uns.$pws) == $_COOKIE['settings']){ echo "Logged in"; break; } } } ?> This will check the db vs the cookie and correctly identify if the cookie is still valid. Problem: If the WHILE turn up no results how can I echo "Please Log In" ... basically I want to stick an ELSE after the while and say 'okay we couldnt find a match so your cookie is out of date, please sign back in' but else is improper syntax. thanks Link to comment https://forums.phpfreaks.com/topic/203048-ive-been-dancing-around-this/#findComment-1063962 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.