简体   繁体   English

如何制作带有自动重定向的登录页面?

[英]How do you make a login page with automatic redirects?

For example:例如:

When I type gmail.com it redirects me to following link当我输入gmail.com它会将我重定向到以下链接

https://accounts.google.com/signin/v2/identifier?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin

Then when I am done logging in, it redirects me to following link然后当我完成登录后,它会将我重定向到以下链接

https://mail.google.com/mail/u/0/#inbox

My question is how can I do this on my website.我的问题是如何在我的网站上执行此操作。 I have the following on any page where the user needs to be logged in.我在用户需要登录的任何页面上都有以下内容。

 session_start();
 require_once 'dbconnect.php';

 // if session is not set this will redirect to login page
 if( !isset($_SESSION['user']) ) {
  header("Location: index.php");
  exit;
 }

So how can I change this code to let the login page know where to redirect after a successful log in?那么如何更改此代码以让登录页面知道成功登录后重定向的位置?

I have the following on my login page.我的登录页面上有以下内容。

ob_start();
 session_start();
 require_once 'dbconnect.php';

 // it will never let you open index(login) page if session is set
 if ( isset($_SESSION['user'])!="" ) {
  header("Location: home.php");
  exit;
 }

How can I change this to redirect to the page?如何更改它以重定向到页面?

First step make GET url the current page第一步使 GET url 成为当前页面

$actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

if you used link make sure the link is如果您使用链接,请确保该链接是

echo '<a href="login.php?q='.$actual_link.'">Login</a>';

Make file login.php for check login制作文件 login.php 以检查登录

session_start();
require_once 'dbconnect.php';

$gotopage = $GET_["q"];

if(!isset($_SESSION['user'])) //Check if error or not isset login and redirects to index.php
{
    header("Location: index.php");
}
else if(isset($_SESSION['user'])) //Check if success login and redirects to home.php
{
    header("Location:".$gotopage);
}

I have found using cookies is easier.我发现使用 cookie 更容易。 I created a cookie with user address before sent to login page, then redirected them back after the completion of login page.我在发送到登录页面之前创建了一个带有用户地址的 cookie,然后在登录页面完成后将它们重定向回来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 你如何用 HTML 制作一个只有一个正确用户名和一个密码的登录页面屏幕? - How do you make a login page screen with HTML which only has one correct username and one password? 当人们进入页面时,如何进行自动滚动 - How do i make a automatic scroll when people go on a page 您如何制作一个单页滚动页面? - How do you make a one scroll page? 如何在不重新加载页面的情况下更改网页? - How do you make a web page change without reloading the page? 我如何制作一个使用特定输入重定向到特定 html 页面的 js 代码? - How do i make a js code that redirects to a certain html page with a certain input? 使用Ionic 2,您如何通过登录后通过模态将登录状态发送到另一个页面的方式来更改按钮? - With Ionic 2 how do you change a button based on login status through a modal that sends you to another page after you login? 如何进行仅在您登录时重定向的 onclick 重定向? - How to make a onclick redirect that only redirects if you're signed in? REST要求登录过程,我们如何处理重定向? - REST calls for login process, how do we handle redirects? 重新加载页面后,如何使网站记住数字? - How do you make websites remember numbers after reloading the page? 如何让整个DIV可点击进入另一个页面? - How do you make the entire DIV clickable to go to another page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM