...

View Full Version : Verifying user error



javanewbie7
04-26-2012, 04:13 PM
OK, I'm taking a PHP/MYSQL Class and am working on project. For this project, we're suppose to create a user login page along with admin pages. Well, I'm following along in the book and typed it line by line, well, the page that verify's the user information keeps saying there's an error. Thinking mistyped, I literally copied and pasted the code. I'm still getting the error.



Here's the error: "Parse error: syntax error, unexpected '{' on line 8". NOTE: This is a beginners class. So, in my opinion, the code below probably isn't the best or the most secure way to do this. However, for this class, we are supposed to do it like the book. Thanks.


<?php
session_start();
// User is logging in
if (isset($_POST["login"])){
if (isset($_POST["username"]) && ($_POST["username"]
== "phpbee")
&& isset($_POST["password"]) && ($_POST["password"]
== "phpbee"){
$_SESSION["Authenticated"] = 1;
}
else{
$_SESSION["Authenticated"] = 0;
}
session_write_close();
header("Location: protected.php");
}
// User is logging out
if (isset($_GET["logout"])){
session_destroy();
header("Location: login.html");

SlayerACC
04-26-2012, 04:27 PM
OK, I'm taking a PHP/MYSQL Class and am working on project. For this project, we're suppose to create a user login page along with admin pages. Well, I'm following along in the book and typed it line by line, well, the page that verify's the user information keeps saying there's an error. Thinking mistyped, I literally copied and pasted the code. I'm still getting the error.



Here's the error: "Parse error: syntax error, unexpected '{' on line 8". NOTE: This is a beginners class. So, in my opinion, the code below probably isn't the best or the most secure way to do this. However, for this class, we are supposed to do it like the book. Thanks.


<?php
session_start();
// User is logging in
if (isset($_POST["login"])){
if (isset($_POST["username"]) && ($_POST["username"]
== "phpbee")
&& isset($_POST["password"]) && ($_POST["password"]
== "phpbee"){
$_SESSION["Authenticated"] = 1;
}
else{
$_SESSION["Authenticated"] = 0;
}
session_write_close();
header("Location: protected.php");
}
// User is logging out
if (isset($_GET["logout"])){
session_destroy();
header("Location: login.html");

You are missing a bracket at the end of this: this is how is should be

if (isset($_POST["username"]) && ($_POST["username"]
== "phpbee"))

and this is what you have:

if (isset($_POST["username"]) && ($_POST["username"]
== "phpbee")
Thanks, Slayer

javanewbie7
04-27-2012, 04:19 AM
Thanks.

Now it's saying "
Parse error: syntax error, unexpected T_BOOLEAN_AND on line 9

I've googled and noticed that it could too many parentheses. I went through the code and it seems to match up. COuld it be something else?

Inigoesdr
04-27-2012, 04:22 AM
Thanks.

Now it's saying "
Parse error: syntax error, unexpected T_BOOLEAN_AND on line 9

I've googled and noticed that it could too many parentheses. I went through the code and it seems to match up. COuld it be something else?

Post your entire updated code. You have an if() condition at the end of your original post that cuts off, but your error is before that.

javanewbie7
04-27-2012, 08:59 PM
Below is the full code for the auth.php page (updated with the first person's suggestions). We were told to go by what's in the book, problem is, there isn't anything after the if statement. I even went to the book's website to dl the source code from the book and it's the same as it is below.



##### begin #####
##### auth.php #####
<?php

session_start();
// User is logging in
if (isset($_POST["login"])){
if (isset($_POST["username"]) && ($_POST["username"]
== "phpbee")) && isset($_POST["password"])
&& ($_POST["password"]
== "phpbee"){
$_SESSION["Authenticated"] = 1;
}
else{
$_SESSION["Authenticated"] = 0;
}
session_write_close();
header("Location: protected.php");
}
// User is logging out
if (isset($_GET["logout"])){
session_destroy();
header("Location: login.html");
}

?>
##### auth.php #####
##### end ####

javanewbie7
04-27-2012, 10:58 PM
Nevermind. I figured it out. That to everyone who helped.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum