Jump to content

Problem Creating Session


neufelni

Recommended Posts

Hello everyone,

 

I am making a website which requires users to login, however, I am often getting the following error when logging in:

 

Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\TCP\pages\Users\Authenticate.php on line 28

 

Here is the code in Authenticate.php that causes the error:

if (md5($_POST["Password"]) == $password)
{
	session_start();
	$_SESSION['logged_in'] = true;
	header('Location: ../Administration/index.php');
}
else
	header('Location: login.php?result=0');

 

Line 28, the line where the error occurs is:

$_SESSION['logged_in'] = true;

 

About half the time it logs in just fine, but the other half I get the error. This error only occurs when the username and password is correct, if it is incorrect it returns to the login page just fine.

 

Does anyone know what could cause this?

 

Thanks,

neufelni

 

Link to comment
https://forums.phpfreaks.com/topic/116720-problem-creating-session/
Share on other sites

You won't get an execution time limit error due to the posted code. You must have a loop of some kind that never exits. Post all your code to get the quickest answer.

 

Also, depending on what code is after the posted lines of code, you need to put an exit; statement after any header() redirect.

Hello, thanks for the replies.

 

I moved session_start to the top of the page, but am still getting this error. Here is the entire Authenticate.php file.

<?php
session_start();
ini_set("display_errors","2");
ERROR_REPORTING(E_ALL);

function __autoload($class_name)
{
	require_once("../../Models/" . $class_name . '.php');
}

if (!ISSET($_POST["Username"]) || !ISSET($_POST["Password"]))
	header('Location: login.php');

$db = new DBConnection();

$query = SQLStatements::SelectPasswordByUserName($_POST["Username"]);
$query = mysql_query($query);

$password = NULL;

while ($row = mysql_fetch_array($query))
{
	$password = $row[0];
}

if (md5($_POST["Password"]) == $password)
{
	$_SESSION['logged_in'] = true;
	header('Location: ../Administration/index.php');
}
else
	header('Location: login.php?result=0');
?>

 

I don't think the index.php file has anything to do with it, since the error says that it occurred in Authenticate.php, and it doesn't begin to load index.php(the address bar remains at Authenticate.php).

 

Also, occasionally I just get a server not responding message instead, like this:

Safari could not open the page “http://tcp.homeip.net:8080/tcp/pages/Users/Authenticate.php” because the server is not responding.

Once again, it occurs when loading Authenticate.php.

 

This problem seems to only occur when I'm running the site from the server where I am currently testing it. I have never had it occur when running it one my local machine. And since the line where it says that the error occurs is $_SESSION['logged_in'] = true; I think it might be a problem with some configuration on the server that's not allowing it to create a session. That's the only thing that makes sense to me.

 

Any ideas?

 

Thanks,

neufelni

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.