Code error help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
56beanie90
Forum Newbie
Posts: 3
Joined: Fri May 02, 2008 4:57 pm

Code error help

Post 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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Code error help

Post 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();
 } 
?>
 
56beanie90
Forum Newbie
Posts: 3
Joined: Fri May 02, 2008 4:57 pm

Re: Code error help

Post 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
Post Reply