Jump to content

if statement and mkdir within luser register script


wrathican

Recommended Posts

hey i have a problem with a register script.
what i want to happen is when a user submits their information and the registration is successful, a directory under their name is created in a specific location.

i assume you can do this using a if statement. so i have created the following one:
[code]$userdir=$_POST['user'];

if($q=success)
{
mkdir("/htdocs/images/gallery/".$userdir, 0777);
}[/code]

if your wondering what $q is, its this:
[code]$q = "INSERT INTO users VALUES ('$username', '$password')";[/code]

when i load up the page i get this warning:
[quote]Warning: mkdir(): open_basedir restriction in effect. File(/htdocs/images/gallery/) is not within the allowed path(s): (/tmp:/usr/share/pear:/home/fhlinux178/g/gallery.ls12style.co.uk/user) in /home/fhlinux178/g/gallery.ls12style.co.uk/user/htdocs/register.php on line 34[/quote]

your help is greatly appreciated
Link to comment
Share on other sites

This means that your host has a restriction in place to only allow writing in certain directories.

You should be able to contact your host to find out where you can create directories.

Look [url=http://uk2.php.net/features.safe-mode]here[/url] for further details

Regards
Huggie
Link to comment
Share on other sites

hey thorpe thanks
the code you suggested definately did something right.
the error message has changed from the above to this:
[quote]Warning: mkdir(/home/fhlinux178/g/gallery.ls12style.co.uk/user/htdocs/images/gallery/): File exists in /home/fhlinux178/g/gallery.ls12style.co.uk/user/htdocs/register.php on line 34
[/quote]
Link to comment
Share on other sites

well i have figured out why i get that error message. its because the initial directories have already been created. when running the script it creates the folder that i want, but it still displays the error.  ???
  >:(
i want it so that it doesnt display the error.

another problem is that from testing it when i come to clean up the mess i made, i cannot delete the folders because i didnt create them. the script did. does this mean i have to use a script to delete them?
Link to comment
Share on other sites

use file_exists() to check and see if the folder exists first before you create it.
[code]<?php
if(!file_exists($folder)){
mkdir($_SERVER['DOCUMENT_ROOT']."/images/gallery/".$userdir, 0777);
} else {
echo "Folder already exists";
}
?>[/code]

Ray
Link to comment
Share on other sites

hey ray, thanks for your help, but that is not my problem.
if i am reading that code right, it is only creating the directory if it doesnt exist in the first place.
but what i want is a piece of code that creates a folder in that directory everytime a user registers with my website.
but only if the registration is sucessful.
would i be better off sending the variable to another php file in that directory with the mk dir function?
Link to comment
Share on other sites

I happen to be working on a site that does just what you want.  I'll go ahead a post a piece of my registration script, it's 100% working.
also note that there's no implemented security such as add_slashes() and whatnot, don't forget to add that.
func.php

[code]
function set_dir($user)
{
$path="users";
$newdir="$path/$user";
mkdir($newdir, 0777);
}


function register_new($username, $password, $passwordb, $email, $terms)
{
$check=@mysql_query("select username, email from filehost_users");
while($row=mysql_fetch_array($check))
{
if($row[0]==$username)
{
$regp=1;
$_SESSION['error'].="<p>That username is already taken.</p>";
}

if($row[1]==$email)
{
$regp=1;
$_SESSION['error'].="<p>That email is already in use by another account.</p>";
}
}
if(!$username)
{
$regp=1;
$_SESSION['error'].="<p>You must specify a username.</p>";
}
if(!$password)
{
$regp=1;
$_SESSION['error'].="<p>You must enter a password.</p>";
}
if(!$email)
{
$regp=1;
$_SESSION['error'].="<p>You must enter an email address.</p>";
}
if($password != $passwordb)
{
$regp=1;
$_SESSION['error'].="<p>The passwords entered do not match.</p>";
}
if(!$terms)
{
$regp=1;
$_SESSION['error'].="<p>You must agree to the Terms & Conditions.</p>";
}

if($regp==1)
{
header("Location: $_SESSION[url]?loc=register");
exit();
}

$register=@mysql_query("insert into filehost_users (username, password, email) values ('$username', PASSWORD('$password'), '$email')");
set_dir($username);
return $register;
}

[/code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.