Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi all,

 

Maybe you could help me finish off the chapter on sessions and cookies that I have been working through. I struggled with bits but finished most of this chapter (11).

 

The problem is I keep getting a parse error of an unexpected '{' in the loggedin.php script after encrypting the session id with md5. This is the last task in chapter 11. The login.php script logs me in but wont display any html or anything except a white screen with the syntax error at the top.

 

Here is my scripts with the md5 call in that parses:

 

loggedin.php.

 

<?php

 

// The user is directed here from login.php

 

session_start(); // Start the session.

 

 

// If no session value is present, redirect the user:

 

// Also validate the HTTP_USER_AGENT!

 

if (!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER ['HTTP_USER_AGENT']) ) {

require_once ('login_functions.php');

$url = absolute_url();

header("Location: $url");

exit(); // Quit the script.

 

}

 

 

 

// Set the page title and include the html header:

$page_title = "Logged In!";

$page_description = "";

include ('header1.php');

include ('nav1.php'); ?>

<div id="mainCont"></div>

 

// Print a customized message:

 

<div id="col1">

 

<?php

 

echo "<h1>Logged In!</h1>

<p>You are now logged in, {$_SESSION ['first_name']}!</p>

<p><a href=\"logout.php\">Logout</a></p>";

?>

 

 

</div>

 

<?php include ('footer1.php');

?>

 

 

 

 

 

And here is the other page which also calls md5; login.php:

 

 

<?php

 

// This page processes the login form submission.

 

// Upon successful login the user is redirected.

 

// Two included files are necessary.

 

// Send Nothing to the web browser prior to the setcookie() lines!

 

// Check if the form has been submitted:

if (isset($_POST['submitted'])) {

 

// For processing the login:

require_once('login_functions.php');

 

// Need the db connection

require_once('mysqli_connect.php');

 

// Check the login:

list ($check, $data) = check_login($dbc, $_POST['email'], $_POST['pass']);

 

if ($check) { // OK!

 

// Set the session data:

session_start();

$_SESSION['user_id'] = $data ['user_id'];

$_SESSION['first_name'] = $data ['first_name'];

 

// Store the HTTP_USER_AGENT:

$_SESSION['agent'] = md5($_SERVER ['HTTP_USER_AGENT']);

 

// Redirect:

$url = absolute_url ('loggedin.php');

header("Location: $url");

exit(); // Quit the script.

 

} else { // Unsuccessful!

 

// Assign $data to $errors for error reporting

// in the login_page.php file.

$errors = $data;

 

}

 

mysqli_close($dbc); // Close the database connection.

 

} // End the main submit conditional.

 

// create the page:

 

include('login_page.php');

 

?>

 

 

 

Any advice, even yeah it happened to all of us, or no it didnt happen to me would be greatly appreciated. Thanks in advance.

Share this post


Link to post
Share on other sites

Sorry folks all better now!

 

Just a typo on line 12 of loggedin.php. There should have been a closing parenthis bracket thing after one of the arrays. I spend too long copying from the book without taking in what I am typing.

 

Thanks anyway, Stu.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×