1
我是Slim框架的新成员,目前我正在为它创建登录和注册服务。PHP slim应用程序未运行?
我在lib中为database.php
创建了一个数据库文件,并将下面的代码放在该文件中以供用户选择数据。
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require 'lib/mysql.php';
class DatabseLayer{
public function __constructor(){
}
public function isUserExist($email, $password){
$dbObject = new DbConnect();
$sql = "Select * from users where email = $email and password = $password limit 1";
$result = mysqli_query($dbObject->getDb(), $sql);
if(count($result) > 0){
return true;
}
return false;
}
}
?>
的话,我已经把下面的index.php文件的代码
<?php
error_reporting(E_ALL);
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require 'vendor/autoload.php';
//require 'lib/mysql.php';
require 'lib/database.php';
$app = new \Slim\App;
$app->get('/:email/:password', function($email, $password){
$password = md5($password);
$databaseObject = new DatabaseLayer();
$isRegistered = $databaseObject->isUserExist($email, $password);
$app = SlimSlim::getInstance();
if($isRegistered){
$app->response->setStatus('200');
$app->response->headers->set('Content_Type', 'application/json');
echo json_encode(Array('isLogin' => '1'));
}else{
echo json_encode(Array('isLogin' => '0'));
}
});
$app->run();
?>
,当我尝试用这个URL
http://localhost/slim/[email protected]/11111
或
http://localhost/slim/index.php/[email protected]/11111
它给了我一个页面未找到错误。我没有更多的想法,任何人都可以帮忙。
请阅读有关mysql注入并使用准备好的语句或至少转义值之前在查询中使用它们。在get url中也有登录凭据是一个坏主意。他们可能会在第三方网站的REFERER头部中显示,并会显示在日志,浏览器历史记录等中 –
您使用的是哪个版本的slim?您似乎将混合Slim 2和Slim 3代码混合在一起。 – meun5