Page 1 of 1

Code error help

Posted: Fri May 02, 2008 5:01 pm
by 56beanie90
Hi guys im new to php and dont know squat in terms of technical stuff.. i have a log in form that looks to have no errors but it keeps coming up with the dredded parse error when testing on the wamp server. I dont have a clue what's wrong so was wondering if anyone can help me..
my code is....

Code: Select all

<?php
  session_start();
  session_register('valid_login');
  session_register('user_id');
  session_register('user_name');
?>
<?php
  $username = $_GET['username'];
  $password = $_GET['password'];
  $userfile = fopen("users.txt", "r") or die ("Yikes");
  
  while (!feof($userfile)) {
    $line = fgets($userfile);
 
    $items = explode("|", $line);
 
if (array_key_exists($username,$passwd) && $passwd[$username] == $password)
{
   $_SESSION['user_id'] = $uid[$username];
   $_SESSION['user_name'] = $username;
   $_SESSION['valid_login'] = true;
   echo "Welcome <p><a href="private.php">Click here to continue.</a></p>";
   exit();
 } else {
   session_destroy();
 }
 
?>
<html>
  <head>
    <title>Login Incorrect</title>
  </head>
As well as this i need to produce a way so the logged in user can post messages on their page and saves to a database- i have no idea how to go about doing that so any help would be great.
thanks in advance

Re: Code error help

Posted: Fri May 02, 2008 5:11 pm
by aceconcepts
Don't use session_register()

Code: Select all

 
<?php
  session_start();
 
  $username = $_GET['username'];
  $password = $_GET['password'];
  $userfile = fopen("users.txt", "r") or die ("Yikes");
 
  while (!feof($userfile)) {
    $line = fgets($userfile);
 
    $items = explode("|", $line);
 
if (array_key_exists($username,$passwd) && $passwd[$username] == $password)
{
   $_SESSION['user_id'] = $uid[$username];
   $_SESSION['user_name'] = $username;
   $_SESSION['valid_login'] = true;
   echo "Welcome <p><a href="private.php">Click here to continue.</a></p>";
   exit();
 } else {
   session_destroy();
 } 
?>
 

Re: Code error help

Posted: Fri May 02, 2008 5:25 pm
by 56beanie90
it didn't like line19 on that so i changed it to

Code: Select all

header("location: private.php");
now it says

Parse error: syntax error, unexpected $end in C:\wamp\www\weblog site\login.php on line 23

i wish programming was so much easier. think i will eventually stick to becoming a web designer than a programmer