Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
666 views
in Technique[技术] by (71.8m points)

php - Google App Engine using PHP7 header() does not redirect the page correctly

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 : redirection issue screenshot


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...