Jump to content

Create a new folder when user register


KYKK

Recommended Posts

I found out that make a new folder is mkdirbut i don't really know how to use it$folder = trim($_POST['folder']); // trim to remove whitespace$folder = $_REQUEST['foldername'];if(is_dir(\"..\$folder"))echo "directory exists!";else{mkdir(\"../'$folder'");echo "folder created";}_____________THE FORM IS_____________<div class="left_box">Your Folder(you put Myclan and your URL will be clanwebsite.co.cc/myclan )</div><div class="right_box"><input type="text" name="folder" size="30"></div>and there problems....what mkdir(\"../'$folder'"); mean , and why there a \ behind the mkdir( ?

Link to comment
Share on other sites

That's not correct, with is_dir either. The single quotes don't belong in mkdir either. It should be like this:

if(is_dir("../$folder"))echo "directory exists!";else{mkdir("../$folder");

That will check for and create a folder with the given name one level up from the folder where the script is running.

Link to comment
Share on other sites

um.. ok.. i put that and directory exists but i don't see it in my file manager why? and ../$folder meaning that it create a folder in the folder that contain myadmin folder right?... likeI have register.php in .com/admin/register.phpand i want to create a folder like.com/nameso should it be ../$folder or ../../$folder?and still i don't see the folder anywhere but it say directory exists will it mean that it created somewhere but i don't see it?

Link to comment
Share on other sites

It will create the folder one level up from the current folder.
That is, one folder up from the folder that contains your PHP script.Does your file manager need to be refreshed? Mine uses a button that looks like 2 green arrows chasing each other in a circle.
Link to comment
Share on other sites

i have cpanel for file manager...and i copy the code to a new file instead of the whole register codes so it easier to find problem the whole code is

<?php$foldername = $_REQUEST['foldername'];if(is_dir("$folder"))echo "directory exists!";else{mkdir("$foldername");}?>    <form action="newfolder.php" method="post">    <input type="hidden" name="page_mode" value="register">Your Folder(you put Myclan and your URL will be clanwebsite.co.cc/myclan)</br><input type="text" name="foldername" size="30">        <div class="left_box"> </div>    <div class="right_box"><input type="submit" value="Register" size="30"></div>

and it showWarning: mkdir() [function.mkdir]: No such file or directory in /home/ksclans/public_html/admin/newfolder.php on line 9BEFORE i type in something in the input box and press registerand it success I see the folder and it work fine, but i don't want that warning it say no such file or directory is it checking to see if there a file on it own? or mkdir is not a function ? but it working.. ? so...

Link to comment
Share on other sites

before i learn your register tips thingy i would ask how i check if form was submitted before press submit but now i can solve it my ownif (is_dir("$foldername")) echo "directory exists!"; elseif ($foldername=="") echo ""; else mkdir("$foldername");________ok now i have a folder how should i add a new folder? like use a command to copy and paste one of the folder in my admin folder and to the user folder or there can be some how create that file + code when it create that folder? so i want when a user register it will create a folder for him like profile... and have it own index.php and index.php is read it own data ... select echo... like that again so what you suggest i should do?

Link to comment
Share on other sites

PHP has a copy function to copy a file. There's no function to copy an entire directory, so you would need to create the directory first and then copy files into it. It sounds like you should be using htaccess and mod_rewrite though. Instead of creating a new folder with a bunch of PHP files that you may need to update individually in the future if your code changes, just have a URL like domain.com/users/name redirect to an address like domain.com/users.php?user=name. The users will still see the other URL in the address bar, but then you can have 1 file handle everything. If you need to change the code you only have 1 file to change. If you want to set that up, search for htaccess and mod_rewrite to see how it's done.

Link to comment
Share on other sites

so you mean if i have a new thing like a new blog thingy and i need to go throught every index.php to add select blog and echo row blog for every thing but if use htaccess then it like use 1 file and add all those? don't really know what htaccess is or mod rewite so i search in google..i found thishttp://www.workingwith.me.uk/articles/scripting/mod_rewriteand which one i mean which function i should really use?I understand that htaccess is like a .php like that and it something.htaccess right?and is mod_rewrite a thing that redirect pages to domain.com/users.php?user=nameso in general are you saying that use the document domain.com/users.php to echo rows - read database info and use ?user=name to select user and when people tell their URL they say domain.com/users/name and use mod_rewrite to redirect pages to their selected user page?

Link to comment
Share on other sites

I understand that htaccess is like a .php like that and it something.htaccess right?
A .htaccess file is a file that goes in any web directory, and it sets rules for that directory and subdirectories. The entire file is called ".htaccess", it's not an extension for another file.
and is mod_rewrite a thing that redirect pages to domain.com/users.php?user=name
More or less. You don't really use mod_rewrite directly, mod_rewrite just needs to be installed. The .htaccess file contains all of the rules that you set up for mod_rewrite. The rules are basically regular expressions that tell Apache what to do with a certain URL. Like look at this link:
http://www.pjstar.com/news_state/x859557338/Canton-not-OK-with-topless-wrestling

(I aplogize if you're not into topless midget wrestling, best example I could quickly find)Notice how they have the title of the story as a part of the link. I guarantee there is not a file on their server with that name, when you go to that link it gets directed to another page. Notice in the link before the story title there's a number there, it looks like an ID number for the story. There is probably a rewrite rule set up on that server to look for URLs in this format:

http://www.pjstar.com/news_state/x[story id]/[story title]

The rule would take that and instead go to a page like this, for example:

http://www.pjstar.com/news.php?id=[story id]

The news.php page would get the story ID and look it up in the database like normal.So you get one URL coming in to the server, but the server turns that into another URL. It's not the same thing as a redirect, because the user's browser never changes. The user always sees the same URL they clicked on, but when the server receives that URL it translates it into something else that it can use. That's what the combination of mod_rewrite and .htaccess files do. You can see that type of thing all over the place on blogs and photo galleries and things where the title of the page is in the link somewhere. People do that because it helps search engine rankings when keywords show up in the URL (even though on the server the URL is changed). If you're trying to set up a system where a user can log in and see their personal home page, that sounds like a good solution for you. Instead of sending the users to duplicate copies of the same PHP page in their own folder, just redirect all of those to a single page that can look up which user it is and show that user's data. The user will still think it's their own page even though you only have one page of code on your server doing all the work.

Link to comment
Share on other sites

The page you linked to has examples.RewriteRule ^alice.html$ bob.htmlThat rule will change any request for alice.html into a request for bob.html. If you send the server a request like this:domain.com/files/users/alice.htmlit will actually load this file:domain.com/files/users/bob.html

Link to comment
Share on other sites

yes i know about that but i don't know what it use for you say you guarantee there is not a file on their server that the link you send... and there 2 doc in the exsample and it html one alice one bob... but how i use it for my exsample? do i really create a .html or php for each user and file to create http://kywebsite.co.cc/alice/alice.html so it can link to some where else? or a rule that just say the URL without needing a real file on the url ? because in the exsample it say make sure both file can read...and what i should put in my "bob" file that work for my thingy.. get what i mean... ?

Link to comment
Share on other sites

You want users to log in and have their own home page, right? So if three people log in they go to these places:domain.com/users/user1domain.com/users/user2domain.com/users/user3So you can do 2 things. One, you can actually create a folder called "users", and inside users you can create a folder for each user, and inside each folder you can put an index.php file that displays information for that user. But, if you need to update the code in your user PHP file, then you have 3 places to update the code because there are 3 copies of the file, one for each user.Or, you can have all of those URLs go to the same place:domain.com/users.php?user=user1domain.com/users.php?user=user2domain.com/users.php?user=user3Now you only have 1 PHP file, users.php, which looks up which user to display information for and displays it. Now you only have to change the code in 1 place. So you set up a rewrite rule to rewrite a URL such as domain.com/users/user1 into domain.com/users.php?user=user1.Is this making any sense at all? I'm trying to explain this the best way I know how but it doesn't sound like you're understanding what I'm saying. It's really easy. Instead of making a bunch of copies of a file and putting it all over the place, have one copy that all of the other URLs point to. That's it, that's all I'm trying to say here. I'm not going to be able to explain to you in English how to set that up because it sounds like you're having problems understanding what I'm saying, so you're probably going to need to look for a reference in your language about how to use mod_rewrite and htaccess files.

Link to comment
Share on other sites

ooo i understand this time lol ok.. and I came from hong kong (china) but i am "american" now... forgot how to read english better but i still learning english came to 3-4 years and didn't read much chineese after i came over...and i can't even type in chineese with computer because i still young before i came over so i didn't "learn" about computer just play computer games before...but I start website thingy this 1-2 year...how you know i learn other language?anyway...so #1 users.php in general you say it is a file that displays information for user as in select - echo row that one we did before this ..

$query = ("SELECT id, name, email, title FROM users WHERE name='{$_SESSION['user_name']}'");$sql = "SELECT * FROM `users` WHERE `name` = '{$_SESSION['user_name']}'";$result = mysql_query($sql);while($row = mysql_fetch_array($result)){echo $row['title'];echo $row['name'];}

that one, and do it say it like that or different way to do that for this kind of thing? #2 users.php?user=user3 is equal user/user3/index.php that done with mod-rewrite ( I asking hosting people if they enable the mod-rewrite or not ...)#3 if it is the same select - echo row ... then need to select which user to show but what is the different between users.php?user=user3users.php?user=user2so my question really is users.php?user=user2 is that a "name" "value" or =user2 that really is meaning? 'hard to explain....um.. so users.php?user=user2how i select to show the link on top the user2 how i get it to the select code?well this for session$sql = "SELECT * FROM `users` WHERE `name` = '{$_SESSION['user_name']}'";and what i do for URL users.php?user=user2$sql = "SELECT * FROM `users` WHERE `id` = 'URL value user='";lol....like what i put in there? or do i even use select back to #1... users.php?user=user2users.php is the file "?" is mod-rewrite ? and user2 is the "name" but what is it call ? like value ? name ?thanks for reading i know it hard to understand...___________________________EDIT:after i ask my hosting people they say it ( the mod_rewrite ) already enabled, i can't get the simple sample work ... I can't create .htaccess without a name to create it but I can add like a.htaccess is that still ok? because in the link for mod_rewrite it say

we’re going to add a couple of lines to your .htaccess file. The .htaccess file is a text file which contains Apache directives. Any directives which you place in it will apply to the directory which the .htaccess file sits in, and any below it. To ours, we’re going to add the following: 

it didn't say to put a name on it I don't know if that make it not working ..... i sure that i can see bob and alice webpage but when i go to alice.html it not showing bob.html stuff...

Link to comment
Share on other sites

back to mod_rewrite:after i ask my hosting people they say it ( the mod_rewrite ) already enabled, i can't get the simple sample work ... I can't create .htaccess without a name to create it but I can add like a.htaccess is that still ok? because in the link for mod_rewriteit say

we’re going to add a couple of lines to your .htaccess file. The .htaccess file is a text file which contains Apache directives. Any directives which you place in it will apply to the directory which the .htaccess file sits in, and any below it. To ours, we’re going to add the following:

it didn't say to put a name on it I don't know if that make it not working ..... i sure that i can see bob and alice webpage but when i go to alice.html it not showing bob.html stuff...do i put down mod_rewrite to likeRewriteRule ^alice.html$ user.php?user=alice.htmlfor every user ? orRewriteRule ^*.html$ user.php?user=*.htmlsome people use like greasymoney and the script work for *.google.com and it mean image.google.com video.google.com so the * is "anything" there do it work for this mod_rewrite too? or do i need to put in RewriteRule ^alice.html$ user.php?user=alice.htmlfor every user?_________________EDITand to your last post I make select GET user... and it work but i need to manually type users.php?user=user1

Link to comment
Share on other sites

I can't create .htaccess without a name to create it but I can add like a.htaccess is that still ok?
The file has to be called ".htaccess", that's the only file that Apache looks for. It isn't going to look for "a.htaccess" or anything else, just ".htaccess".You're on the right track with wildcards in the URL, you'll want to look for a pattern (the user name) and use that same pattern in another place (in the $_GET variable). The rewrite rules are regular expressions, if you look up regular expressions you should be able to find plenty of help. You'll want to set up a regular expression to match the URL you're looking for and then say how you want it to be transformed. There is quite a bit of help for people trying to set this type of thing up, I just haven't done much of it myself. I found this on one site:to converthttp://www.xyz.com/abc/jklto http://www.xyz.com/prog.php?request=abc&am...erparameter=jklas well.<IfModule mod_rewrite.c>RewriteEngine OnReWriteRule ^/(.*)/(.*)$ /prog.php?request=$1&otherparameter=$2ReWriteRule ^/(.*)$ /prog.php?request=$1</IfModule>There are 2 rules there, the first rule converts a URL of the form /var1/var2 into /prog.php?request=var1&otherparameter=var2. The second rule converts a URL like /var1 into /prog.php?request=var1. The (.*) in the expression is a match to make that you can use in another place. The first match is $1, the second match is $2, etc.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...