elementis0 Posted November 21, 2007 Share Posted November 21, 2007 ok heres my problem I downloaded a script called filethingie and what it does is lets users register accounts to login and manage their files. the only problem with the script that I need to change is that in the script you have to manually add the users editing a little pre-made script they give you. But I dont want to manually add each user, I want to query the users from an already made database instead. I kind of have a rough idea of how to do it but I keep running into major problems.the original code to add users was this: # in order to Additional users use this#/*$users['REPLACE_WITH_USERNAME']['password'] = "REPLACE_WITH_PASSWORD";$users['REPLACE_WITH_USERNAME']['dir'] = "REPLACE_WITH_CUSTOM_DIRECTORY";*/#example of additional users added$users['Awakened']['password'] = "5f4dcc3b5aa765d61d8327deb882cf99";$users['Awakened']['dir'] = "users/Awakened";$users['basketball4life']['password'] = "051496ed1891991abe3126b5260de7f9";$users['basketball4life']['dir'] = "users/basketball4life"; except I dont wanna manually handle users with php, i just wanna use the database system so i tried to tweak the code to where it gets each user name with an array in a while loop. but its not working since when the variables go outside the while loop its not an array going through each member anymore which renders the code useless when other parts of the script try to read it.here was how i tried to fix it: $con = mysql_connect(DB_SERVER,DB_USER,DB_PASS);mysql_select_db(DB_NAME,$con);$userinfo = mysql_query("SELECT * FROM wp_users");while($row = mysql_fetch_array($userinfo)){global $username, $password, $users;$username = $row['user_login'];$password = $row['user_pass'];$users[$username]['password'] = $password;$users[$username]['dir'] = "users/".$username;} but this code doesnt help since the other parts of the script dont read it right. what can I do to make it so the users already in the database can just log in, so i dont have to manually add them.the whole filethingie script can be found here:http://www.solitude.dk/filethingie/download.php Link to comment Share on other sites More sharing options...
justsomeguy Posted November 21, 2007 Share Posted November 21, 2007 You've got the right idea. If the $users array has a password and dir element for each user it looks like you're building it the right way. You don't need to use global variables though, and you don't need to use temporary variables. This should work: $userinfo = mysql_query("SELECT user_login, user_pass FROM wp_users");while($row = mysql_fetch_array($userinfo)){ $users[$row['user_login']]['password'] = $row['user_pass']; $users[$row['user_login']]['dir'] = "users/".$row['user_login'];} You can prove to yourself that the array gets built correctly by printing it after the while loop finishes:print_r($users); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.