$ _GET请求返回undefined

时间:2017-05-17 15:03:19

标签: javascript php angularjs

我有一个试图连接谷歌日历的角度项目,这样我就可以提交预订,并自动添加gmail日历。这是有效但不是在正确的情况下。这是我为了让它正常工作所遵循的example

我有一个角度项目,在登录时将检查Web应用程序是否有权使用日历。返回时,它使用GET将令牌保存到会话,但是使用$_GET返回时,redirectUrl未定义。即使param是URL中的。我认为这要归结为角度布线。

登录时,我会检查是否已设置$_SESSION['token'],如果没有通过javascript重定向。 $authUrl = $this->client->createAuthUrl();然后{j}重定向location.href = $authUrl。这很好用,用户接受权限并重定向回下一页www.example.co.uk/index/dashboard?code=4%2F5NgsMp8JepEmXVgR8pez0fQdk_jTPonsuExdV8&authuser=0&session_state=2dfb836cfc217135f907c7e6c0d9c526983b6f..9103&prompt=none

但是当我尝试$_GET['code']时,这是未定义的,这意味着此方法无法运行以设置令牌:

if (isset($_GET['code'])) { 
         $this->client->authenticate($_GET['code']);
         error_log("tou can access");
         $_SESSION['token'] = $this->client->getAccessToken();
         $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 
         header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));

     }

print_r($_GET);字段:

Array ()

.htacces规则:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase 
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*) /index.php/#/$1
</IfModule>

更新 这个错误是因为我从一个未被设置为标题的ajax请求加载一个单独的php。一旦我将要插入的GET请求重新定位到与标题匹配的文件中,就可以了。

1 个答案:

答案 0 :(得分:-1)

您需要在重写中包含查询字符串标志...

https://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase 
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*) /index.php/$1 [QSA]
</IfModule>
相关问题