[英]Slim php framework 3 passing email in argument not working
我在苗條的PHP框架3中遇到錯誤。
“在此服務器上找不到請求的資源/try/foo@bar.com/secret。”
我是苗條的PHP框架的新手。 當我輸入電子郵件地址“ foo @ bar ”和密碼“ secret ”時,將產生一個空白錯誤(即""
)。 當我輸入電子郵件地址“ baz ”和密碼“ secret2 ”時,它不會產生任何錯誤消息。
我基本上是為Android提供網絡服務,用戶將在其中輸入電子郵件地址和密碼,並且所需的查詢將以JSON格式返回。
$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);
});
@
不是網址中的有效字符:(請參閱https://stackoverflow.com/a/1856809/1172363 )
您必須使用帶有Urlencoded電子郵件值的鏈接來創建鏈接...
$app->urlFor("your_route_name", array("email" => urlencode($mail), "password" => urlencode($password));
以您的情況為例(例如):
實際上,我通過使用Base64邏輯對參數進行編碼解決了這個問題。
btoa(條件)
在端點(我的是PHP)中,我執行了base64decode操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.