dpiz9879 2016-02-05 12:39
浏览 20

如果使用PHP直接访问,则将访问者重定向到另一个页面

I have a register.php page, which allows visitors to register to become certain users. If they meet all requirements set by the form validation, they will be redirect to another page, called thankyou.php page.

My question is if anyone tries to visit the thankyou.php page directly without going through/ from the register.php page, then it should redirect them back to the register.php page again.

Note: I know how to use the $_session = array(); for the logged-in users, and header() function very well. Once again, the question here requires some kind of research on how to restrict visitors from accessing thankyou.php directly (because visitors have not become users of the website yet).

Please don't guide me in jquery or javascript or any other languages. I need your help in php.

Thank you!

  • 写回答

4条回答 默认 最新

  • douba8819 2016-02-05 12:48
    关注

    You have to check first if the $_SESSION variable associated with the correct redirect to thankyou.php is setted.

    After that, you have to check if the user $_SERVER['HTTP_REFERER'] meets the requirements, that is if $_SERVER['HTTP_REFERER'] (that contains the referral url) ends with register.php and the domain is your domain.

    I suggest you to do something like (I'm assuming you defined a constant YOUR_HOST and used a session variable ok. Change it with yours as well):

    if(empty($_SESSION['ok']) || empty($_SERVER['HTTP_REFERER'])) {
        die(header('Location /register.php'));
    }
    
    $url = parse_url($_SERVER['HTTP_REFERER']);
    if($url['host'] !== YOUR_HOST || $url['path'] !== 'register.php') {
        die(header('Location /register.php'));
    }
    // else show the thankyou page content
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看