Jump to content

cant figure this out......


Recommended Posts

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 post
Share on other sites

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 post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...