Createing directory

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Createing directory

Post by josh »

I need to have it so that when the admin logs in he can create a user.. the user is inserted into a database and same with his password

Then I need to create user/clients/$user/index.php user/clients exists but I need to create directory user/clients/$user then put index.php


index.php uses the users password and username in it so for instance if username is bob:

Code: Select all

<?php
session_start();
$pass= $_REQUEST&#1111;'pass'];
$user = $_REQUEST&#1111;'user'];

echo("<body bgcolor=#DAF9FE>");

if($user=="bob" and $pass=="bobspassword")&#123;

echo("Welcome bob!<BR><BR>");



echo("<BR><BR><a href='../../logout.php'>Logout</a>");
&#125; else &#123;
echo("No Acess, please login first");
&#125;
?>
That would be index.php ^^^

I need every instance of bob to be relevant to the username etc...

So how would I go about createing a directory then a file? I already coded the database parts of it and the login checks if in the database bob's pass is "bobspassword" then presents the following code..

Code: Select all

if ($dbpass==$pass) &#123;

		echo("<a href='clients/$user/index.php?user=$user&pass=$pass'>Welcome $user, click here to goto your welcome page</a>");
&#125;
I wanted to use sessions but the file i include to read the database and verify the password outputed the headers already.. and if i put start_session(); before i require db.php (the password checker) then db.php will just say invalid pass even if its correct
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

Code: Select all

mkdir("path/to/new/dir/and/the/dirs/name");
//then to copy the index.php file use
copy("dir/to/file/to/be/copied/plus/file/name", "copy/destination/and/file/name");
hope that helps
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

how do i change certaint things in the new file once i write it?
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

put some holder in place of the name like:

welcome %%REPLACEMENAME%%

then use str_replace(%%REPLACEMENAME%%, Bob, $indextext) to change it
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

k thanks... i use the following code to write to a file... how could i modify it to change things in the file?

Code: Select all

$outputstring = "blah";
@ $fp = fopen("../test4/index.php", "a");
if (!$fp)
&#123;
    echo "<p><strong> Your Addition could not be processed at this time.
         Please try again in a few minutes. Extra fields were left in the database that you need to clean / compleate addition manually</strong></p></body></html>";
    exit;
&#125; 
fwrite($fp, $outputstring);
fclose($fp);
echo "<center><p><b><a href="index.php">Click Here to continue</a></b></p></center>";
I replaced "$user" with "test4" because I am running this code from test.php in the same directory as createasuer.php that way my database isn't full of test1 test2 test4 test5 etc...
Post Reply