500 ( Internal Server Error)

Website URL

http://winchester-crud.rf.gd/configs/login.php

Error Message

500 ( Internal Server Error)

Other Information

I’m trying to make a login with InfinityFree MySQL using the file getUser.php, but when this file is read, he returns an internal error, as if the database had something wrong. Tried the same method through localhost in my desktop, but all worked normally. What should I do?

getUser.php:

<?php session_start(); ?>

<?php
    function getUser($name, $pass) {

        include "../database/database.php";

        $conn = OpenCon();

        $sql = 'SELECT * FROM admin WHERE name = "' . $name . '"' ;
        $result = $conn->query($sql);

        if (mysqli_num_rows($result) > 0) {

            while($row = $result->fetch_assoc()) {

              if ($pass != $row['password']) {
                header("Location: ../index.php?error=invalid_password");
                die();
              };

              setToken($conn, $name);

              header("Location: ../dashboard/user.php");
            }
          } else {

            header("Location: ../index.php?error=invalid_user");
          };
    };

    function setToken($conn, $name) {

      $_SESSION["token"] = generateToken();

      $sql = "UPDATE admin SET token='" . $_SESSION["token"] . "' WHERE name='" . $name . "'";
      $conn->query($sql);
    }

    function generateToken($length = 16) {
      $stringSpace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
      $pieces = [];
      $max = mb_strlen($stringSpace, '8bit') - 1;
      for ($i = 0; $i < $length; ++ $i) {
           $pieces[] = $stringSpace[random_int(0, $max)];
      }
      return implode('', $pieces);
    };
?>

database.php:

<?php

    function OpenCon() {

        $envPath = 'env.ini';
        $env = parse_ini_file($envPath);

        $conn = new mysqli($env["dbhost"], $env["dbuser"], $env["dbpass"], $env["db"]);

        return $conn;
    };

    function CloseCon($conn) {
        $conn -> close();
    };
   
?>

Hi and welcome to the forum.

Your localhost has a different database environment than InfinityFree’s (and any other provider)

Please read this article in order to troubleshoot.

6 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.