重定向回索引页面 [英] Redirecting back to index page
问题描述
我有一个名为index.php的主页.还有一个名为registration.php的注册页面.
I have a home page called index.php.. And a registration page called registration.php.
index.php中包含一些逻辑,需要执行这些逻辑才能使站点正常工作.
The index.php has some logic in it that needs to be executed inorder for the site to work properly.
因此,可以说网址是 http://www.testwebsite.com
,注册网址为:因此,假设该网址为 http://www.testwebsite.com/registration.php
and the registration url is: So lets say the url is http://www.testwebsite.com/registration.php
当用户立即导航到时,可以说url是 http://www.testwebsite.com/registration.php index.php中的逻辑被绕过,未执行并导致问题.
When a user just immediately navigates to So lets say the url is http://www.testwebsite.com/registration.php the logic in index.php gets bypassed and is not executed and causes problems.
现在问一个问题.
如果他们直接转到registration.php链接,是否可以将它们重定向到index.php页面?因此,代码必须检查并查看是否首先点击了index.php网页,如果未点击,则应将其重定向到index.php.但是,如果index.php网站已经被点击,那么它应该继续运行,而不应该重定向回index.php.
Is there a way for me to redirect them to the index.php page if they ever go to the registration.php link directly? So the code has to check and see if the index.php webpage was hit first, if it was not hit then it should redirect to index.php. But, if the index.php site was already hit then it should just continue and not redirect back to index.php.
推荐答案
执行"index.php"后,您可以创建会话变量,如下所示:
When "index.php" is executed you can create a session variable, like this:
<?php
session_start();
$_SESSION[ "index" ] = TRUE; // CREATE SESSION VARIABLE.
?>
现在,在"registration.php"中检查会话变量:
Now, in "registration.php" you check for the session variable:
<?php
session_start();
if ( ! isSet( $_SESSION[ "index" ] ) ) // IF SESSION VARIABLE DOES NOT EXIST.
header( "Location: index.php" ); // JUMP TO INDEX.
?>
这两个代码都必须在其相应页面的顶部.
Both of these codes must be at the top of their corresponding pages.
这篇关于重定向回索引页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!