Slim framework is not directing the login route

Asked

Viewed 293 times

0

Good afternoon! I am doing a PHP7 course project, but I have the following problem:

Fatal error: Uncaught Error: Call to undefined function Slim\Http\get_magic_quotes_gpc() in C:lojavirtual\vendor\slim\slim\Slim\Http\Util.php:59 Stack trace: #0 C:lojavirtual\vendor\slim\slim\Slim\Http\Request.php(240): Slim\Http\Util::stripSlashesIfMagicQuotes(Array) #1 C:lojavirtual\vendor\slim\slim\Slim\Middleware\MethodOverride.php(88): Slim\Http\Request->post('_METHOD') #2 C:lojavirtual\vendor\slim\slim\Slim\MiddlewarelPrettyExceptions.php(67): Slim\MiddlewarelMethodOverride->call() #3 C:lojavirtual\vendor\slim\slim\Slim\Slim.php(1159): Slim\Middleware\PrettyExceptions->call() #4 C:\lojavirtual\index.php(44): Slim\Slim->run() #5 {main} thrown in C:lojavirtual\vendor\slim\slim\Slim\Http\Util.php on line 59 

Error image

The codes that were created:

USER.php

class User {
public static function login($login, $password){
    $sql = new Sql();
    $results = $sql->select("SELECT * FROM tb_users WHERE deslogin = :LOGIN", array(
        ":LOGIN"=>$login
    ));
    if (count($results) === 0)
    {
        throw new \Exception("Falha no Login!");
    }
    $data = $results[0];
    if (password_verify($password, $data["despassword"]) === true)
    {
        $user = new User();
        $user->setiduser($data["iduser"]);

    } else {
        throw new \Exception("Falha no Login!");
    }
}
}

Model.php

<?php
namespace Hcode;

class Model {
    private $values = [];
    public function __call($name, $args){
        $method = substr($name, 0, 3);
        $fieldName = substr($name, 3, strlen($name));

        var_dump($method, $fieldName);
    }
}
?>

Slim’s route

$app->post('/admin/login', function() {
    User::login($_POST["login"], $_POST["password"]);
    header("Location: /admin");
    exit;
  • Odd function get_magic_quotes_gpc be being called here... What version of the Slim Framework are you using? Or else, where you downloaded it?

  • Good afternoon! Sorry for the delay to reply, but I’m using version 2.0

2 answers

-1

I believe you should be with the directive magic_quotes_gpc disabled on your machine. You need to enable it on php.ini:

; Magic quotes para dados vindos via GET/POST/Cookie.
magic_quotes_gpc = On
    
; Magic quotes para dados gerados em tempo de execução,ex.: dados vindo de SQL, de chamadas à exec(), etc.
magic_quotes_runtime = On
    
; Usar magic quotes no estilo Sybase (escapar ' com '' ao invés de \').
magic_quotes_sybase = On

The function get_magic_quotes_gpc is obsolete since PHP 7.4.0 and even with the above correction you will continue to receive a message like this:

Deprecated: Function get_magic_quotes_gpc() is deprecated in...

Of course, since you are following a course, it is better to use the same version of the teacher’s framework (it is worth checking if the one he is using is the same as yours), however, the ideal for "real" projects is to use the new Slim version, due to this and other improvements.

-2

Between HTTP vendor/slim, edit the Util.php file and replace the function code (instead of using the function get_magic_quotes_gpc() as it is there, replace it with the logical value false)

public static function stripSlashesIfMagicQuotes($rawData, $overrideStripSlashes = null)
{
    $strip = is_null($overrideStripSlashes) ? false : $overrideStripSlashes;
    if ($strip) {
        return self::_stripSlashes($rawData);
    } else {
        return $rawData;
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.