almightyegg Posted February 5, 2007 Share Posted February 5, 2007 when somebody signs up to my site they are given an address like www.mysite.com/username but I would like to add a file aswell as the directory (i can make the directory fine) and the file will be a redirect to the mainsite. Is there anyway to add a file to it? ??? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted February 5, 2007 Share Posted February 5, 2007 1. what kind of file do you want to add (please give the file type extension, is it like .txt, .html, .php or/....?etc?) 2. where about do you want to place this file? TEd Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 5, 2007 Author Share Posted February 5, 2007 .php and when somebody signs up they will get: mysite.com/username and i would like the file to be index.php in that directory so mysite.com/username/index.php Quote Link to comment Share on other sites More sharing options...
tarun Posted February 5, 2007 Share Posted February 5, 2007 Ive Come Up With This  $newfile = "username/$username.php"; $file_pointer1 = fopen("$newfile", "a"); fwrite($file_pointer1, "content"); fclose($file_pointer1); Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted February 5, 2007 Share Posted February 5, 2007 <?php $file = fopen("$username/index.php","w");$write = fwrite($file,' <?php //your php page contents ?>');fclose($file); ?> one thing to notice, becareful when you are locating your index.php file, since you have just created your username folder, therefore, you have to use the same variable to locate it, noticed i used "$username". Ted Quote Link to comment Share on other sites More sharing options...
tarun Posted February 5, 2007 Share Posted February 5, 2007 Also How Do You Create Directorys Beacause Thats Something Ive Wanted To Know But I Havent Got Round To It  Thnx, Tarun Quote Link to comment Share on other sites More sharing options...
marcus Posted February 5, 2007 Share Posted February 5, 2007 You could use mod rewrite  RewriteEngine On RewriteRule ^users/([^/]*)$.php /users.php?user=$1  $1 would be ?user=USERNAME Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 5, 2007 Author Share Posted February 5, 2007 some of these ideas dont make much sense to me, and the omnes that do, I've tried and they come up with errors any other ideas? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 5, 2007 Share Posted February 5, 2007 mod_rewrite is really the best solution for what you want to do. Here is a great article: http://www.sitepoint.com/article/guide-url-rewriting Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 6, 2007 Author Share Posted February 6, 2007 where would i find my httpd.conf file :-X I can't find it in my files. There is .htaccess and .errorlog but no httpd.conf Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 6, 2007 Author Share Posted February 6, 2007 Also How Do You Create Directorys Beacause Thats Something Ive Wanted To Know But I Havent Got Round To It  mkdir() Quote Link to comment Share on other sites More sharing options...
Balmung-San Posted February 6, 2007 Share Posted February 6, 2007 where would i find my httpd.conf file :-X I can't find it in my files. There is .htaccess and .errorlog but no httpd.conf  Assuming a Linux machine, it's usually under /etc/httpd/httpd.conf, however this differs based on the environment. As well, your web host may not allow you to edit it. I have no idea where the file resides on Windows, but I think it's in the apache directory. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 6, 2007 Author Share Posted February 6, 2007 it's not there. Maybe my host doesn't allow it then. Is there any raw code I could use instead to auto redirect www.mysite.com/username to www.mysite.com/profile.php?id=userid ??? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 6, 2007 Share Posted February 6, 2007 Did you try using mod_rewrite? It might already be enabled...move on to the next step in the article, or call your host. Quote Link to comment Share on other sites More sharing options...
Balmung-San Posted February 6, 2007 Share Posted February 6, 2007 Wasn't there an article on the main site recently about clean urls without mod rewrite? That involves custom error pages though, so if your host doesn't allow them (though most do), that won't work either. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 6, 2007 Author Share Posted February 6, 2007 Did you try using mod_rewrite? It might already be enabled...move on to the next step in the article, or call your host. Â i thought everything was done in the httpd.conf file??? Â Wasn't there an article on the main site recently about clean urls without mod rewrite? That involves custom error pages though, so if your host doesn't allow them (though most do), that won't work either. Â I have custom error pages yes, do you know where this article is? Quote Link to comment Share on other sites More sharing options...
Balmung-San Posted February 6, 2007 Share Posted February 6, 2007 http://www.phpfreaks.com/tutorials/149/0.php  There you go. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 6, 2007 Share Posted February 6, 2007 Did you try using mod_rewrite? It might already be enabled...move on to the next step in the article, or call your host. Â i thought everything was done in the httpd.conf file??? Â No, it's done in the htaccess file. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 6, 2007 Author Share Posted February 6, 2007 how do you use the htaccess file? I tried opening it but I don't have the software... Quote Link to comment Share on other sites More sharing options...
Balmung-San Posted February 6, 2007 Share Posted February 6, 2007 how do you use the htaccess file? I tried opening it but I don't have the software... Â .htaccess is just a plain text file. You can open it with any text editor. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 6, 2007 Author Share Posted February 6, 2007 nope...I just did that and some of it is understandable but some is all squiggles and ascii symbols Quote Link to comment Share on other sites More sharing options...
Balmung-San Posted February 6, 2007 Share Posted February 6, 2007 nope...I just did that and some of it is understandable but some is all squiggles and ascii symbols  That's part of how .htaccess works. For example:  RewriteEngine On RewriteRule ^users/([^/]*)$.php /users.php?user=$1  from the first page would rewrite anything from the /their_username/ folder with a .php extension to users.php?user=their_username. At least I believe that's how I understood the post. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 6, 2007 Author Share Posted February 6, 2007 oh this is so god damn confusing!! would I not have to label the folder with the username varible too??  Are you sure there's no simple way to redirect www.mysite.com/username to www.mysite.com/userpage.php?id=$userid  that's why I originally was going to create a file on sign up in their directory called index.php whihc would redirect but most people said I'd need mod_rewrite for that too Quote Link to comment Share on other sites More sharing options...
Balmung-San Posted February 6, 2007 Share Posted February 6, 2007 Actually, that article I pointed you to would do just what you need. Â Just make your 404 page, then strip the URI like it says, and redirect to www.mysite.com/userpage.php?id=$stripped_uri_var. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted February 6, 2007 Author Share Posted February 6, 2007 but even that confused me. I will browse the net for some script or other 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.