0

Recently I've been trying to code a simplistic login system for my website, with a lot of errors I have been facing it seems to be going back and forth in unsurety for what to do.

The error message that I am receiving is Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967296 bytes) on line 17 of index.php I had a look on stackoverflow to see what the cause of the problem might be, and I tried the answer found here

Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967296 bytes)

But sadly changing longtext to mediumtext in phpmyadmin still had no effect, In fact it stopped returning any error_log and just reloaded my webpage! If you head over to beastfox.com You can see that all that happens is when entering my test username and password that I have added to the database (username:Username password:Password) It causes a HTTP ERROR 500.

I am slightly unsure of what to do, since it apparently has something to do with my index.php I have listed the code as shown below,

<?php
   include("database.php");
   session_start();

   if($_SERVER["REQUEST_METHOD"] == "POST") {
      // Create querystring
      $sql = "SELECT password FROM admin WHERE username = ?";

      // Prepare, bind, execute
       if (!$stmt = mysqli_prepare($mysqli,$sql)) {
    echo "Failed to prepare:".mysqli_error($mysqli);
    return;
}
      $stmt = mysqli_prepare($mysqli,$sql);
      mysqli_stmt_bind_param($stmt, 's', $_POST['username']);
      mysqli_stmt_execute($stmt);
      mysqli_stmt_bind_result($stmt, $user_password);
      if (mysqli_stmt_fetch($stmt)) {
         // Validate password
         if (password_verify($_POST['password'], $user_password)) {
             session_register("username");
             $_SESSION['login_user'] = $username;

             header("location: myaccount.php");
            exit;
         } else {
             $error = "Your Login Name or Password is invalid";
         }
      mysqli_stmt_close($stmt);
      } else {
         $error = "Your Login Name or Password is invalid";
      }
   }
?>

And according to the error_log it says its due to line 17 (mysqli_stmt_bind_result($stmt, $user_password);)

As in the other persons stack overflow here i'll list my version etc

PHP Version: 5.6

libmysql - 5.1.73:

memory_limit: 168M

Thanks a billion if you think you have any ideas on what the problem is!

If anything else is needed I will honestly try anything,

I will keep looking just incase but currently everything I have tried does not seem to be working.

  • Find the config file of your php server and increase that limit. – Sv Sv Jul 15 '17 at 16:50
  • @SvSv I'd much rather figure out what's causing PHP to attempt to allocate FOUR GIGABYTES. – Niet the Dark Absol Jul 15 '17 at 16:51
  • @NiettheDarkAbsol I could be wrong here, but related to what the error_log stated it is something due to line 17 on my index.php? –  Jul 15 '17 at 16:53
  • Use some php debugger/profiler. – Sv Sv Jul 15 '17 at 16:53
  • @SvSv What you are saying isn't really helping matters to the greatest extent. I have no idea how to use a php debugger and I am not exactly sure on how I am meant to do that, –  Jul 15 '17 at 16:57
  • 1
    Possible duplicate of [Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967296 bytes)](https://stackoverflow.com/questions/18121619/allowed-memory-size-of-134217728-bytes-exhausted-tried-to-allocate-4294967296-b) – Progman Jul 15 '17 at 17:01
  • I don't know if this is your case, but in my case, after unsuccessfully trying all solutions posted, we discover that was related with a problem of discrepances in database. – Carmen Jul 15 '17 at 17:01

1 Answers1

1

As already stated in your linked question the problem is binding a result variable for a TEXT column.

You don't need a TEXT column for your password hash, a sufficient VARCHAR(255) column will be enough. Change your password hash column to that type.

Progman
  • 16,827
  • 6
  • 33
  • 48
  • Thank you so much! The only problem with doing this (Which I have tried similarly alread,) Is that no error_log is returned in my ftp after doing so, And all it does is reload the page (Or do something) But no error_log is created after clicking Submit. –  Jul 15 '17 at 17:05