Jump to content


Sessions Encrypted With Md5

  • Please log in to reply
2 replies to this topic

#1 stupidStu



  • Members
  • Pip
  • 2 posts

Posted 25 March 2012 - 5:43 PM

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:



// 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">


echo "<h1>Logged In!</h1>
<p>You are now logged in, {$_SESSION ['first_name']}!</p>
<p><a href=\"logout.php\">Logout</a></p>";


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

And here is the other page which also calls md5; login.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:

// Need the db connection

// Check the login:
list ($check, $data) = check_login($dbc, $_POST['email'], $_POST['pass']);

if ($check) { // OK!

// Set the session data:
$_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:



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

#2 stupidStu



  • Members
  • Pip
  • 2 posts

Posted 25 March 2012 - 6:50 PM

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.
  • 0

#3 Larry



  • Administrators
  • 4916 posts
  • LocationState College, PA (USA)

Posted 26 March 2012 - 8:00 AM

Glad you figured it out and thanks for letting us know.
  • 0