Hello !
I tried to make an API with Slim Framework, but when I launch my url path I a have a blank page, not a 404 error’s page but an totally white page.
Have you any ideas ?
Here my api:
<?php
require 'class/Slim/Slim.php';
\Slim\Slim::registerAutoloader();
//require 'vendor/autoload.php';
$app = new \Slim\Slim();
require 'class/CorsSlim.php';
$corsOptions - array(
"origin" => "*";
"exposeHeaders" => array("Content-Type", "X-Requested-With", "X-authentication", "X-client"),
"allowMethods" => array('GET', 'POST', 'PUT', 'DELETE', 'OPTIONS')
);
$cors = new \CorsSlim\CorsSlim($corsOptions);
$app->add($cors);
//connexion
$app->get('/connection/:identifiant/:pass', function($login, $password){
$serveur = "localhost";
$dbname = "racehistory";
$user = "root";
$mdp = "root";
$con = mysql_connect($serveur, $user, $mdp);
mysql_select_db($dbname, $con);
$data = array();
$login = htmlspecialchars($login);
$login = strtolower($login);
$password = htmlspecialchars($password);
if(!preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#", $login)){
$errors['email'] = 'adresse mail non valide';
}
if(!preg_match("#^(?=.*[A-Z])(?=.*[a-zA-Z])(?=.*\d)([\w]{8,15})$#", $password)){
$errors['pass'] = 'mot de passe non conforme, majuscule, 8 caractères min';
}
if(!empty($errors)){
$data['success'] = false;
$data['errors'] = $errors;
}
else{
$event = "SELECT * FROM users WHERE mail='".$login."'";
//autre event pour la sauvegarde du jeu plus tard
$even = mysql_query($event);
while($ret = mysql_fetch_assoc($even)){
$id = $ret["ID"];
$mail = $ret["mail"];
$pass = $ret["password"];
//sauvegarde jeu
}
if($id){
if($pass == $password){
echo "test";
$data['success']= true;
//good
}
else{
$errors['mail'] = 'Adresse mail introuvable';
$data['success'] = false;
$data['errors'] = $errors;
}
}
}
mysql_close($con);
echo jscon_encode($data);
});
$app->run();
//replace mysql_connect by mysql PDO look at this php
?>
Thank You