比方说,用户进入“profile.php”页,但它需要登录。 然后它重定向到登录页面。 但登录后,应回重定向到profile.php页面。 我怎么做?
如何获取当前URL在PHP?
$ _SERVER [ 'URI'] ????
比方说,用户进入“profile.php”页,但它需要登录。 然后它重定向到登录页面。 但登录后,应回重定向到profile.php页面。 我怎么做?
如何获取当前URL在PHP?
$ _SERVER [ 'URI'] ????
大多数网站简单地传递到登录表单,像这样的变量:
redirect(login.php?returnUrl=original_page.php);
然后登录处理后,它会重定向到其RETURNURL所指向的页面。 如果没有RETURNURL变量,然后调用默认的(的index.php或如default.php)。
希望这有助于。
为了得到当前页面的URL CONCAT $_SERVER["SERVER_NAME"]
和$_SERVER["REQUEST_URI"]
。
你可以做的就是创建一个会话变量,当你检测到用户需要登录。然后把它重定向到登录页面,办理签约后,你确认他的证件是正确的,你可以从会话检索值和重定向他到页面,他请求。
I don't know if this is the best method, but I used to solve this like this. In pages which requires login, say in your case "profile.php", i 'll issue a new session, just to remind the browser you cam from this page. And then in login page after validating the credential if the user is legitimate, then Ill check if there is any page specific session. If so I'll redirect to that page.
in pseudocode
First in profile.php
if(!isset($_SESSION['login'])
header('Location: login.php');
in login.php, after checking
if(isset($_SESSION['profile'])
header('Location: login.php');
else
header('Location: index.php');
It sometime since I used PHP, so the code may be rusty but you can follow a logic like this. Once again, there may be better options. Do research.