Forum Moderators: coopster

Message Too Old, No Replies

Simple login script and form giving T_VARIABLE error

         

methnen

5:31 am on Nov 30, 2004 (gmt 0)

10+ Year Member



I know next to nothing about php scripting and have this relatively simple login script that asks for a login and pass word from a form and then redirects the user to another page. It won't run and I can't figure out how to get it to run. Any help would be greatly appreciated.

Here is the form:
<form action="verify.php" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value=" Login ">
</form>

Here is what I have in verify.php:
<?php

  $username = $HTTP_POST_VARS['username'];
  $password = $HTTP_POST_VARS['password'];

  // location of page to go to if username and password match
  $url = "protected.php";

  $user_array = array("protected");
  $pass_array = array("files");
  $user_length = count( $user_array );

  for ( $i = 0; $i < $user_length; $i++ )
  {
    if ( $username == $user_array[$i] && $password == $pass_array[$i] )
    {
      session_start();
      session_register("user");
      session_register("loggedIn");
      $_SESSION['user'] = $username;
      $_SESSION['loggedIn'] = "true";

      header("Location: $url");
    }
  }

  // nothing became valid while we looped so verification failed
  echo '<b>Verification Failed!</b>';

?>

I get the unexpected T_Variable error on line 3 of the verify.php script.

This is on a IIS server with PHP 4.2.x installed. I have no control over any settings. And yes Global_Variables are off and it is not an option to turn them on.

Thanks again for any help you can give.

Jamie

jatar_k

9:46 pm on Nov 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld methnen,

I pasted that cod einto a file and loaded it into my browser and got no parse errors at all.

Do you have nay more info? Is there something that you didn't paste? What exactly is line 3? I am assuming the username or password assignment line.

methnen

10:12 pm on Nov 30, 2004 (gmt 0)

10+ Year Member



Thank you for the welcome. :)

Yes line 3 is the password line.

That is basically all of the information I can provide.

<snipped url>

The script runs fine on my server as well but I'm running Apache and PHP from a Linux box so I'm thinking it has something to do with the IIS and PHP installation from the Windows box that I need to use the script on. I was hoping there was some standard problem with this setup that has a workaround.

[edited by: coopster at 11:13 pm (utc) on Nov. 30, 2004]
[edit reason] removed url per TOS [webmasterworld.com] [/edit]

coopster

11:26 pm on Nov 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you certain it is the verify.php script that is failing at line 3 and not protected.php or perhaps the login script itself?

methnen

12:07 am on Dec 1, 2004 (gmt 0)

10+ Year Member



Yes. It is indicated in the error which I apparently shouldn't post since it contains a web address in it. :) Sorry about that.

There really isn't a login script, just the form which as you can see is pretty basic. It calls the verify.php script which is then supposed to take the submitted contents of the username and password fields and see if they match the username and password specified in the verify.php script.

protected.php is just a simple html page at the moment that displays "This Page Is Protected"

Jamie

coopster

12:29 am on Dec 1, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




Yes. It is indicated in the error which I apparently shouldn't post since it contains a web address in it. :) Sorry about that.

Actually, the link was to your phpinfo() page which only gives the PHP configuration. But that doesn't matter, apology accepted ;)

I can't see anything here that should be causing any parse error either. Is this the entire script?

methnen

12:55 am on Dec 1, 2004 (gmt 0)

10+ Year Member



That is the entire script. So I'm taking it the problem has something to do with the setup of the server and not the PHP script itself?

Jamie

coopster

1:19 am on Dec 1, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Could be. How about the
always_populate_raw_post_data
directive? I notice it is Off. Maybe something going on here?