0

I am having an error with slim PHP framework 3.

"The requested resource /try/foo@bar.com/secret was not found on this server."

I am new to slim PHP framework. When I enter email address "foo@bar" and password "secret" it yields a blank error (i.e. ""). When I enter email address "baz" and password "secret2" then it yields no error message.

I am basically making web service for Android, where the user will enter an email address and password and the required query will be returned in JSON format.

$app - > get('/try/{email}/{password}', function($request, $response, $args) {
    include_once('db.php');




    $email = $request - > getAttribute('email');
    echo $email;
    $password = $request - > getAttribute('password');
    echo $password;

    $sql = "select * from user where email='$email' and password='$password'";
    echo $sql;
    $result = mysqli_query($con, $sql);

    if (mysqli_num_rows($result) > 0) {
        // output data of each row
        $data[] = mysqli_fetch_assoc($result);
        header('Content-Type:application/json');
        echo json_encode($data);

    } else {
        echo "0 results";
    }

    mysqli_close($con);

});
Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
fahad pirzada
  • 103
  • 10
  • For me it does work. I'm using XAMPP, what are you using? show us your .htaccess file – jmattheis Jan 17 '17 at 19:55
  • I am using wamp . RewriteEngine On RewriteCond %{Request_Filename} !-F RewriteCond %{Request_Filename} !-d RewriteRule ^ public/index.php [QSA,L] – fahad pirzada Jan 17 '17 at 19:58
  • It works for me, but the difference is that I have the .htaccess file in the public/ directory rather than the root. – Rob Jan 17 '17 at 20:36
  • Include an example curl request and response with headers to help to understand what request you are actually doing. – Mika Tuupola Jan 18 '17 at 08:22

2 Answers2

1

@ is not a valid character inside an url: (see https://stackoverflow.com/a/1856809/1172363)

You must create your link with urlencoded email value...

$app->urlFor("your_route_name", array("email" => urlencode($mail), "password" => urlencode($password));

In your case it would be (for example):

http://yourserver/try/foo%40bar/your_pass

Community
  • 1
  • 1
Pipe
  • 2,379
  • 2
  • 19
  • 33
0

Actually I solved this problem by encoding the parameter with Base64 logic.

btoa(criteria)

In the endpoint (mine is PHP) I did a base64decode operation.

diy_nunez
  • 97
  • 1
  • 7