Is there a way so that a particular page is opened only if it is referred from somewhere on the same website and does not opens if direct URL is entered? I want the results page of my Quiz website to work this way. Any help? Please ask for any more details or explanations needed. I would prefer the functionality in php.
2条回答 默认 最新
- douchenbiao0916 2013-11-21 16:50关注
You could access
$_SERVER["HTTP_REFERER"];
. However, you certainly can't rely on it as it can be easily spoofed. The best option is to set a session variable on page A, which they will need in order to access page B. Very basic example:page-a.php
session_start(); $_SESSION['page_a_visited'] = true; //Display HTML and link to page-b.php, etc.
page-b.php
session_start(); if(!isset($_SESSION['page_a_visited'])){ //Directly accessing the page without having visited Page A. //Or session has expired. exit; }
In response to your comment. If your quiz needs to force the user to navigate from Question 1 through to Question 10:
Instead of
$_SESSION['page_a_visited'] = true;
, use something like$_SESSION['page_a_visited'] = $questionId;
When they're on Question 2, make sure that$_SESSION['page_a_visited']
exists and that it is equal to 1. When they're on Question 3, make sure that$_SESSION['page_a_visited']
exists and that it is equal to 2. And so on.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
- ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
- ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
- ¥15 帮我写一个c++工程
- ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
- ¥15 关于smbclient 库的使用
- ¥15 微信小程序协议怎么写
- ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
- ¥20 怎么用dlib库的算法识别小麦病虫害
- ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启