Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: memory problem

  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    memory problem

    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:
    PHP Code:
    <?
    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($resultMYSQL_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!

    Last edited by sts1202; 01-07-2012 at 01:00 PM. Reason: resolved

  • #2
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,281
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Glad you've got it fixed, you're clearly getting the hang of debugging your code
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •