...

View Full Version : Resolved memory problem



sts1202
01-06-2012, 04:25 PM
Hi,
First time so hope this makes sense!

I get an error saying that my PHP script has gone over my 32MB limit:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 19456 bytes) in /home/y15alst/public_html/site1/loginauth.php on line 24.

I have tried upping the memory up to 64MB using ini_set('memory_limit', '64M') which did not work, but instead on going up and up, I would rather have some help on why it happened in the first place.

Here is my script:


<?
session_start();
$myusername = $_POST['myusername'];
$mypassword = $_POST['mypassword'];
// connect to database here
$myusername = mysql_real_escape_string($myusername);
$query = "SELECT password, salt
FROM users
WHERE username = '$myusername';";
$result = mysql_query($query);
if(mysql_num_rows($result) < 1) //no such user exists
{
echo "Sorry, your login was not successful, please try again";
include_once('index.php');
die();
}
$userData = mysql_fetch_array($result, MYSQL_ASSOC);
$hash = hash('sha256', $userData['salt'] . hash('sha256', $mypassword) ); //THIS IS LINE 24
if($hash != $userData['password']) //incorrect password
{
echo "Sorry, your login was not successful, please try again";
include_once('index.php');
die();
}
if($userData['group'] == "User"){
echo "You are authorised as a user. If you are not $username, please log out now.";
} elseif($userData['group'] == "Superuser"){
echo "You are authorised as a Superuser. If you are not $username, please log out now.";
}
if(!function_exists('validateUser'))
{
function validateUser()
{
session_regenerate_id (); //this is a security measure
$_SESSION['valid'] = 1;
$_SESSION['userid'] = $userid;
}
}
if(!function_exists('isLoggedIn'))
{
function isLoggedIn()
{
if(isset($_SESSION['valid']) && $_SESSION['valid'])
return true;
return false;
}
}
if(!isLoggedIn())
{
echo "Sorry, you do not seem to be authorised";
include_once('index.php');
die();
}
else
{
include('homepage.php');
}
?>


Sources on the web have just suggested upping and upping the memory limit, but I would rather get to the root cause. Others have said you need to clear specific variables but I don't think this can apply to me as I need to keep using them.

Thanks very much for any help that you can give!

:)

sts1202
01-07-2012, 01:00 PM
I've actually fixed the problem myself...

What was happening was that the page the script was outputting to if all conditions were met (homepage.php) was re-routing it back to loginauth.php making it run out of memory.
So, I will just set this to resolved.

tangoforce
01-07-2012, 01:23 PM
Glad you've got it fixed, you're clearly getting the hang of debugging your code :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum