I've been at this webiste business for a year+, and have known html for about half that. Now i've started php, and i'm trying to convert my site to php, and add a (very) simple login script. I've modified it to store the &loggedink or logged in value in a session. It used to bring you to a page to change your info after you logged in, and i changed it to just show logged in as $username along with stesting and edit links. it worked fine, except coming back to index, then it could only display login, even though the session was still active. then I tried to change it, and i messed something up. now i get parse error, unexpected $ in /home/virtual/site5/fst/var/www/html/mr/login.php on line 148 (last line is 147) so poor little me is confuesd. I'm sorry i'm bugging you with this, but I can't figure it out
any help would be appreciated...
Code: Select all
<?
/*
SCRIPT TREE
>function def
>check session
>action=login
>action=edit
>action=change info
>all else
*/
//Create loggedin function
function loggedin($username)
{
echo "<h4>You are currently logged in as $username</h4>";
echo "<a href='index.php?action=edit'>Edit info</a><br />";
echo "<a href='stest.php'>Session test</a>";
}
//Create error_message function
function error_message($message, $username, $password)
{
echo "<H3> $message;</H3>";
echo "<form action='$PHP_SELF' method='post'>";
echo "<P>Username: <input type='text' name='username' value='<?echo $username;?>' class='i' /> /><br />";
echo "Password: <input type='password' name='password' value='<?echo $password;?>' class='i' /> /><br />";
echo "<input type='submit' value='Login' src='login.png' /></p>";
echo "</form>";
}
//If you're still logged in set $logink and display loggedin
if($_SESSIONї'logink'] == "true")
{
$logink = "true";
loggedin($username);
}
/* Simple Signup/Login script
Created on: Feburary 22, 2001
Copyright© 123 Make Me! All Rights Reserved.
To get this script, goto http://123-makeme.com
This Software is free and can be modified and redistributed
under the condition that the copyright and information above
stays intact and with the script.*/
#User Variables
$datafile="/home/virtual/site5/fst/var/www/html/mr/data.txt";
#End User Variales
#If the call for the script is to log them in, DO IT!
if($action == "login"):
#This makes sure all fields are filled out.
if((!$username)or(!$password))
{
#If there is one missing, send them to the error.
error_message("One or more required fields were left blank!", $username, $password);
}
#Open the datafile and login the user.
$file=file($datafile);
while(list(,$value)=each($file))
{
list($fname,$femail,$furl,$fuser,$fpass,$blank)=split( "\|", $value);
if($username==$fuser and $password==$fpass or $_SESSIONї'logink'] == "true")
{
loggedin($username);
$logink="true";
$_SESSIONї'logink'] = "true";
}
}
if($logink==""):
error_message("Login failed, bad username/password<br /> OR you haven't logged in at all.", $username, $password);
endif;
elseif($action=="edit"):
{
echo "<FORM action='$PHP_SELF?action=change' method='post' /><br />";
echo "<P>Name: <input type='text' name='name' value='$fname' class='i' /><br />";
echo "E-mail Address: <input type='text' name='email' value='$femail' class='i' /><br />";
echo "Website Address: <input type='text' name='url' value='$furl' class='i' /><br />";
echo "Password: <input type='text' name='newpass' value='$fpass' class='i' /><br />";
echo "Current Username: <input type='text' name='username' value='$username' class='i' /><br />";
echo "Current Password: <input type='text' name='password' value='$password' class='i' /><br />";
echo "<input type='submit' value='Change'><br />";
echo "</p>";
echo "</FORM>";
}
elseif($action=="change info"):
#This makes sure all fields are filled out.
if((!$name)or(!$email)or(!$url)or(!$username)or(!$password))
{
#If there is one missing, send them to the error.
error_message("One or more required fields were left blank! Please re- login.", $username, $password);
}
#Open the datafile and login the user.
$file=file($datafile);
while(list(,$value)=each($file))
{
list($fname,$femail,$furl,$fuser,$fpass)=split( "\|", $value);
if($username==$fuser && $password==$fpass)
{
$oldword="$fname|$femail|$furl|$fuser|$fpass|";
$newword="$name|$email|$url|$username|$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 = "1";
echo "Everything was changed successfully! <A HREF="$PHP_SELF?action=login&username=$username&password=$newpass">Edit Again</ A>";
}
}
if(!$succ):
error_message("Login failed, bad username/password", $username, $password);
endif;
else:
{
If(!$_SESSIONї'logink'])
{
echo "<FORM action='$PHP_SELF;?action=login' method='post'>";
echo "<P><b>Username: </b><input type='text' name='username' class='i' /><br />";
echo "<b>Password: </b><input type='password' name='password' class='i' /><br />";
echo "<input type='submit' src='login.png' alt='Login' /></p>";
echo "<a href='signup.php'>New? Sign up!</a>";
echo "</form><br />";
}
elseif($_SESSIONї'logink'] == "true")
{
echo "";
}
}
?>