Total noob in PHP need help with creating new folders I want to create a new page for every new “username†Mydomain.com/user1 Mydomain.com/user2 I also put in the username on the page but that is ok but what I do not know is how do create new pages automatically. Creating 1000 folders will take some time
If you have your users stored on a mysql database, you could use a for loop to parse al the data on the mysql table and create a new folder with each user. For example: <?php mysql_connect($host, $user, $pass); mysql_select_db($db); $query_users = "SELECT * FROM users"; $result_users = mysql_query($query_users); $num_result_users = mysql_num_rows($result_users); for ($i_users=0; $i_users <$num_result_users; $i_users_id++) { $row_users = mysql_fetch_array($result_users); mkdir($row_users['user'], 0755); } sleep(1); } ?> PHP: This example code will parse all the entries of the mysql users table and create a folder with the name of the user field and 0755 permissions.
Thanks a bunch. Is there a way i can change the pages inside the folders as well? I am trying figure out if i should use pages, subdomains or folders
Hmm, have you not thought of using mod_rewrite to point all the folders to a main handling script? /user/[id] --> /user.php?id=[id] This allows you to only edit one file, to do everything... Dan
If it was inside foreach, most probably to execute the script slowly. :| Lets wait for dannet to respond though.
Sorry was my error, it should be: for ($i_users=0; $i_users <$num_result_users; $i_users_id++) { $row_users = mysql_fetch_array($result_users); mkdir($row_users['user'], 0755); sleep(1); } PHP: The sleep is to wait after every directory creation and not to charge the server creating the 1000 folders at same time, its optional of course.
Try this: <?php $R1 = mysql_query('SELECT `username` FROM `users`') or die(mysql_error()); if (mysql_num_rows($R1) == 0) { die('Nothing to do.'); } while ($r = mysql_fetch_array($R1)) { $uname = stripslashes($r['username']); $uname = urlencode($uname); mkdir($uname, 0755); } die('All done.'); ?> PHP: That will clean the username up to be safe for a directory name.