Hi all,

Today I read a thread by QWaz that just have been marked as solved. So, I think I should start a new thread with a prefix Tutorial as you are reading now.

I'm going to cover in this tutorial are:

- Create a directory after registering a new user. Let's say if a user name is 'Surya' then it's user name and password will be saved into database and a directory will be created as user name and files from source directory will be copied into it automatically using PHP script

- How you can pass different parameters in a same page. Let's say you have a page index.php and after submitting data through forms you'll remain in your index page but with URL index.php?action=submit.

So here we go..

First we create a database for example : `mydata` then execute this query -

  `username` varchar(50) NOT NULL,
  `password` varchar(100) NOT NULL,
  PRIMARY KEY  (`username`)

Now create aconfig.php file that will contain following details:

// Author : Surya Raj Tripathi
// email-Id: raj.surya19@gmail.com
$DBHost = 'localhost'; // Host address
$DBUser = 'root'; //your database username here
$DBPass = 'vertrigo'; //your database password here
$DBName = 'copytest'; //your database name here
$DBTable = 'user'; // Your table name here
$SourceDir = 'source'; // Your Source directory name here
$con = mysql_connect("$DBHost", "$DBUser", "$DBPass")or die(mysql_error()); //connect to host server 
if (!$con)
  die('Could not connect: ' . mysql_error());

mysql_select_db("$DBName", $con)or die(mysql_error());// select database

Let's create ourcopy.php file and paste this:

// This source code is copied from http://php.net/manual/en/function.copy.php 
// Real author of this code is gimmicklessgpt at gmail dot com
function recurse_copy($src,$dst) { // recursive function that copy files from one directory to another
    $dir = opendir($src);
    while(false !== ( $file = readdir($dir)) ) {
        if (( $file != '.' ) && ( $file != '..' )) {
            if ( is_dir($src . '/' . $file) ) {
                recurse_copy($src . '/' . $file,$dst . '/' . $file);
            else {
                copy($src . '/' . $file,$dst . '/' . $file);

	//echo "$src";

It's OK, now create ourindex.php file and paste the following code:

<?php // Author : Surya Raj Tripathi
// email-Id: raj.surya19@gmail.com?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<title>User registration</title>
<style type="text/css">
border:1px dashed grey;
border:1px solid grey;

	padding:10px 0 2px 5px;
require_once('config.php'); // include config file
require_once('copy.php'); // include copy file that have copy function.
<div class="center">
<h1>Please Enter the details shown below..</h1>

<form action="index.php?action=submit" method="post">
<table class="table" align="center">

<td>User Name:</td>
<td><input type="text" name="uname" /></td>
<td><input type="password" name="pwd" /></td>
<td>Click on Submit..</td>
<td><input type="submit" value="Submit" name="action"/></td>
if($_POST["action"]=='') // check for parameter if action=submit or not if it is blank then show this message
echo "Please fill 'User Name' and 'Password' above!";
if($_POST["uname"]==''){ // if username left then check for password field
   if($_POST["pwd"]==''){ // if it also blank then show this message
echo "You leave both the fields blank. Please fill them and then click on submit to continue.";
 else {echo "User Name field can not be left blank."; // else show user name left blank
elseif ($_POST["pwd"]==''){ // if username is there then check for a null password
echo "Password field can not be left blank.";
   // We will add User into database here..
   $query="INSERT INTO $DBTable (username, password)
// We are doing it for an example. Please encrypt your password before using it on your website
if (!mysql_query($query,$con))
  die('Error: ' . mysql_error());
echo "1 record added ";
 // Now Create a directory as User Name.
 mkdir(dirname(__FILE__)."/"."$username"); // Create Directory
 recurse_copy($SourceDir,$username); // Copy files from source directory to target directory
 // Finally print the message shown below.?> 
Welcome <?php echo $_POST["uname"]; ?>!
You are account folder with name <?php echo $_POST["uname"]; ?> has been created successfully.


Before executing this script please remember to create a folder named Source that contain some files into it so that, you can understand its working properly.

Complete source files can be found here in attached zip file


I hope you like this tutorial. Thanks for giving visiting this thread and giving your valuable time to it.


Recommended Answers

All 3 Replies

Find the user Happygeek and pm him tutorials and over a few weeks or whatever they may eventually put thm in the tutorials tab :)

Thanks metalix, for informing me about this.

i f i login as username or registered then the url becomes http://username.ddd/ like this how to get tutorial is to copy the files if again login then above url hav to come

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.