|
-
Apr 19th, 2007, 04:14 PM
#1
Thread Starter
Junior Member
Error in my php code?
Hi all can anyone please help me with this problem i have in the code below :
The detail does not store in the specified file I don't know why? I did create a users folder out side web server root and the users file inside the user folder.
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registration</title>
</head>
<body>
<fieldset>
<?php include "header.php"; ?>
<h3>Please type your details</h3>
<?php /*script to handle and display HTML form also register user by storing
their information in a text file and create a directory for them*/
//handle the form
if (isset ($_post['submit']))
{
$problem = false;//boolean to chack a state of problem or not, initialised to false
// no problem
// check username value of the form
if (empty($_post['username']))
{
$problem = true;
print '<p> Please enter your name</p>';
}
// check password value of the form
if (empty($_post['password']))
{
$problem = true;
print '<p> Please enter a password</p>';
}
// check validation of entered password (confirmation)
if ($_post['password1'] != $_post['password2'])
{
$problem = true;
print '<p> Your password not match confirmed password</p>';
}
// check if there weren't any problem
if(!$problem)
{
// open the file
if($fp = fopen('..\users\users.txt', 'ab'))
{
//create the data to be written and close the file.
$dir = time () . rand(0, 4596);
$data= $_post['username'] . "\t" . crypt($_post['password1']) . "\t" .$dir . "\r\n";
//write data to and close the file.
fwrite($fp,$data);
fclose($fp);
// create the directory
mdir('../users/$dir');
// print a meessage
print '<p> You are registered</p>';
}
// forgot a field
else
{
print '<p> Please try again</p>';
}
}
else
{// could not write to the file
//print '<p><you could not be registered due to system error</p>';
}
}
// display the form
else
{
?>
<form action="new.php" method ="post">
Username <input type = "text" name ="username" size ="20"><br/>
Password <input type = "password" name ="password1" size ="20"><br/>
Confirm Password <input type = "password" name ="password2" size ="20"><br/>
<input type = "submit" name ="submit" value = "Register"><br/>
</fieldset>
</form>
<?php
}// end of submit if
?>
</body>
</html>
-
Apr 19th, 2007, 04:42 PM
#2
Re: Error in my php code?
do you have the right permissions to write to a text file inside that directory? if you're using a unix based server OS, make sure you've chmodded the directory to allow you write permission. if you're using a windows server, make sure that the user running your webserver has the ability to write files to it.
also, I'd suggest using a different hash algorithm other than crypt(). md5 or sha would both work better, if at all possible.
I'd also suggest to try to always use forward slashes for directories to keep from confusing yourself. it probably isn't the source of your problem, though, because you're using single quotes rather than double. if you used black slashes in your filepaths with a double quoted string, PHP will think you're trying to escape some characters by using a single backslash. either way, you should try to be consistent (your mkdir() call used forward slashes, while your fopen() call used back slashes).
-
Apr 19th, 2007, 05:17 PM
#3
Thread Starter
Junior Member
Re: Error in my php code?
Ok thanks alot for your time and help i really apperciate many thanks mate.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|