PDA

View Full Version : My logon system doesn't seem to register.



iAdam
18-02-2008, 07:24 PM
Thats the code below but everytime I try and register it says that the username is already registered but the datafile is empty. I'm stuck.



<html>
<head>
<title>Register</title>
</head>
<body>


<?php
//php user script
//ben speakman


$datafile = 'data.txt';


if($_GET['action'] == 'signup') {

if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['url']) || !isset($_POST['username']) || !isset($_POST['password'])){

error_message('One or more required fields were left blank!', $_POST['name'], $_POST['email'], $_POST['url'], $_POST['username'], $_POST['password']);
}

$file = file($datafile);
while(list(,$value)=each($file)){ //check if user exists
list($fname,$femail,$furl,$fuser,$fpass,$blank)=sp lit( "\|", $value);
if($username==$fuser){

error_message('Username is allready in use.', $_POST['name'], $_POST['email'], $_POST['url'], $_POST['username'], $_POST['password']);
}
}

$fp = fopen($datafile, 'a');
fwrite($fp, $_POST['name'] . '|' . $_POST['email'] . '|' . $_POST['url'] . '|' . $_POST['username'] . '|' . $_POST['password'] . "|\n");
fclose($fp);
//html for sucessfull signup
?>


You have been sucessfulle registered.<br>
You may now <a href="user.php">login</a> using the followin details <br>
username: <?echo $username;?> <br>
password: <?echo $password;?>


</body>
</html>


<?php
} else {
//html for sign up
?>


<html>
<head>
<title>Register</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" TYPE="text/css">
</head>
<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">




<FORM action="<?php echo $_SERVER['PHP_SELF']; ?>?action=signup" method="post">


<p>Name:
<INPUT type="text" name="name"></p>


<p>E-mail Address:
<INPUT type="text" name="email"> </p>


<p>Website Address:
<INPUT type="text" name="url"> </p>


<p>Desired Username:
<INPUT type="text" name="username"> </p>


<p>Password:
<INPUT type="password" name="password"> </p>


<INPUT type="submit" value="Sign-up">
</FORM>
</body>
</html>




<?php
}
function error_message($message, $name, $email, $url, $username, $password) {
?>


<html>
<head> //html for signing up error
<title>Error</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" TYPE="text/css">
</head>
<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">


<?php echo $message;?> //error message


<FORM action="<?php echo $_SERVER['PHP_SELF']; ?>?action=signup" method="post">

<P>Name: <INPUT type="text" name="name" value="<?php echo $name;?>">


<P>E-mail Address: <INPUT type="text" name="email" value="<?php echo $email;?>">


<P>Website Address: <INPUT type="text" name="url" value="<?php echo $url;?>">


<P>Desired Username: <INPUT type="text" name="username" value="<?php echo $username;?>">

<P>Password: <INPUT type="password" name="password" value="<?php echo $password;?>">


<P><INPUT type="submit" value="Sign-up">
</FORM>
</body>
</html>




<?php
exit;
}
?>


</body>
</html>

DeejayMachoo$
18-02-2008, 09:30 PM
havent read ur code but is your flatfile chmodded too 777?

iAdam
18-02-2008, 09:42 PM
No it isn't, sorry for being a noob but how do I do that?

<?PHP>
19-02-2008, 07:00 AM
Go onto your ftp program, right click file, chmod/edit permissions, 777, OK

iAdam
19-02-2008, 03:40 PM
Did that but now there's an error, I'll post it in a min.

Ok now it just doesn't register, It stills says username is in use but the error is gone and data file is chmodded to 777

Blob
19-02-2008, 03:49 PM
<html>
<head>
<title>Register</title>
</head>
<body>


<?php
//php user script
//ben speakman


$datafile = 'data.txt';


if($_GET['action'] == 'signup') {

if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['url']) || !isset($_POST['username']) || !isset($_POST['password'])){

error_message('One or more required fields were left blank!', $_POST['name'], $_POST['email'], $_POST['url'], $_POST['username'], $_POST['password']);
}

$file = file($datafile);
while(list(,$value)=each($file)){ //check if user exists
list($fname,$femail,$furl,$fuser,$fpass,$blank)=sp lit( "\|", $value);
if($_POST['name'] == $fuser){

error_message('Username is allready in use.', $_POST['name'], $_POST['email'], $_POST['url'], $_POST['username'], $_POST['password']);
}
}

$fp = fopen($datafile, 'a');
fwrite($fp, $_POST['name'] . '|' . $_POST['email'] . '|' . $_POST['url'] . '|' . $_POST['username'] . '|' . $_POST['password'] . "|\n");
fclose($fp);
//html for sucessfull signup
?>


You have been sucessfulle registered.<br>
You may now <a href="user.php">login</a> using the followin details <br>
username: <?echo $username;?> <br>
password: <?echo $password;?>


</body>
</html>


<?php
} else {
//html for sign up
?>


<html>
<head>
<title>Register</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" TYPE="text/css">
</head>
<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">




<FORM action="<?php echo $_SERVER['PHP_SELF']; ?>?action=signup" method="post">


<p>Name:
<INPUT type="text" name="name"></p>


<p>E-mail Address:
<INPUT type="text" name="email"> </p>


<p>Website Address:
<INPUT type="text" name="url"> </p>


<p>Desired Username:
<INPUT type="text" name="username"> </p>


<p>Password:
<INPUT type="password" name="password"> </p>


<INPUT type="submit" value="Sign-up">
</FORM>
</body>
</html>




<?php
}
function error_message($message, $name, $email, $url, $username, $password) {
?>


<html>
<head> //html for signing up error
<title>Error</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" TYPE="text/css">
</head>
<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">


<?php echo $message;?> //error message


<FORM action="<?php echo $_SERVER['PHP_SELF']; ?>?action=signup" method="post">

<P>Name: <INPUT type="text" name="name" value="<?php echo $name;?>">


<P>E-mail Address: <INPUT type="text" name="email" value="<?php echo $email;?>">


<P>Website Address: <INPUT type="text" name="url" value="<?php echo $url;?>">


<P>Desired Username: <INPUT type="text" name="username" value="<?php echo $username;?>">

<P>Password: <INPUT type="password" name="password" value="<?php echo $password;?>">


<P><INPUT type="submit" value="Sign-up">
</FORM>
</body>
</html>




<?php
exit;
}
?>


</body>
</html>

iAdam
19-02-2008, 03:51 PM
Have u corrected anything?

Blob
19-02-2008, 03:52 PM
Have u corrected anything?

Just try it.

iAdam
19-02-2008, 04:03 PM
Thankyou thats worked but now I cant login it always says username/password bad combination or something.


<?php
//php user script
//ben speakman
session_start();
header("Cache-control: private");
?>
<html>
<head>
<title>Logged-in</title>
</head>
<body>
<?php

$datafile="data.txt"; //name of the data file
if($_GET['action'] == "login") {

if(!isset($_POST['username']) || !isset($_POST['password'])){ //this checks that all the fields are filled in

error_message("One or more required fields were left blank!", $username, $password);
}

$file = file($datafile);
while(list(,$value) = each($file)) {
list($fname,$femail,$furl,$fuser,$fpass,$blank) = explode('|', $value);
if($_POST['username'] == $fuser && $_POST['password'] == $fpass){

$_SESSION['name'] = $fuser;
$_SESSION['realname'] = $fname;
$_SESSION['url'] = $furl;
$_SESSION['email'] = $femail; //adds the users data to the php session
$_SESSION['pass'] = $fpass;

//insert html for sucessfull log on here
//you can use . $_SESSION['name'] . for username
// replace name with realname, url, email to display different name
?>
you are logged in.<br>
view you profile <a href="profile.php">here</a><br>
or logout <a href="logout.php">here</a>.
</body>
</html>

<?php
$logink = true;
}
}
if($logink !== true) {
?>
Login failed, bad username/password
<?
}
} elseif($_GET['action'] == 'change') {

if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['url']) || !isset($_POST['newpass'])) {

//this checks that all the fields are filled in
?>
all fields were not filled in
<?
}

$file = file($datafile);
while(list(,$value) = each($file)){
list($fname,$femail,$furl,$fuser,$fpass) = explode('|', $value);
if($_SESSION['name'] == $fuser){
//opens data file to change it
$oldword = "$fname|$femail|$furl|$fuser|$fpass|";
$newword = $_POST['name'] . '|' . $_POST['email'] . '|' . $_POST['url'] . '|' . $_SESSION['name'] . '|' . $_POST['newpass'] . '|';
$fp = fopen($datafile, 'r');
$data = fread($fp, filesize($datafile));
fclose($fp);
$newdata = str_replace($oldword, $newword, $data);
$fp = fopen($datafile, 'w');
fwrite($fp,$newdata) or die ('error writing');
fclose($fp);
$succ = true; //data changed sucessfully
?>
Everything was changed successfully please <a href="user.php">login</a>
<?
$_SESSION['name'] = FALSE;
$_SESSION['pass'] = FALSE;
$_SESSION['url'] = FALSE;
$_SESSION['realname'] = FALSE;
$_SESSION['email'] = FALSE;
}
}
if($succ !== true) {
?>
Login failed, bad username/password
<?
}
} else {
exit;
}
?>

Want to hide these adverts? Register an account for free!