I tried to use the header() function to redirect after user authentication on GAE.
And I tried to get some ideas on GAE documents but cannot seem to find anything about header() function on that.
I found one question which is similar to this but it seems only work on php55
Google App Engine GAE - PHP header('Location: xxx.php') - Error: Not Found - The requested URL was not found on this server.
The problem is after the user authentiacation, I can see the url has changed to main.php on address bar but the head and body remained the same as login.php after deploying.
Here is my app.yaml
runtime: php73
entrypoint: serve login.php
handlers:
- url: /.*
script: auto
- url: /main.php
script: auto
- url: /login.php
script: auto
And login.php
<?php
include_once('index.php');
if(isset($_POST['userId']) && isset($_POST['password'])){
$key = $datastore->key('user', $_POST['userId']) ;
$user = $datastore->lookup($key);
if(!is_null($entity)){
header("Location: main.php");
exit;
}
else{
echo 'User id or password is invalid';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h3>Please enter your details</h3>
<form action='login.php' method='POST'>
<input type='text' name='userId' value='' placeholder='User Id'>
<input type='password' name='password' value='' placeholder='password'>
<input type='submit' name='login' value='Login'>
</form>
</body>
</html>
main.php
<!DOCTYPE html>
<html>
<head>
<title>Main</title>
</head>
<body>
<h2>Main Page</h2>
</body>
</html>
And the problem showed like this :
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…