douwei1128 2016-05-29 12:35
浏览 17
已采纳

通过键入URL阻止直接访问网页

So I'm hosting my website (let's call is abc.com) on goDaddy.

I have a login page (abc.com/login.html).

Which takes me to a second page called booking (abc.com/booking.html) once the login credentials are verified.

So I don't want people to be able to just type abc.com/booking.html and access it. I want them to go to abc.com/login.html and then go to abc.com/booking.html

So I came across 2 ways to fix this -

  1. Include a validating php script in booking.html and changing the extension from html to phtml. -> This didn't work for me
  2. Include a .htacess file. -> I'm not really sure how to do that
  • 写回答

3条回答 默认 最新

  • dongrongdao8902 2016-05-29 13:02
    关注

    so your login screen should already have session code implemented into it that has a variable that specifies if the user is logged in or not. If you don't have that implemented yet, the code would look similar to:

    <?php session_start();//at the very top of the page
    ?>
    //... your own code
    //if the user successfully logs in then:
    $_SESSION['authenticated']=true;
    

    Then on the booking.php page (it should be php to allow php scripts which is super important for validating if a user is logged in), you would then check if the user did log in. If he did, the rest of the page loads, if he didn't, you would redirect them to login.php:

    at the very top of booking.php:

    <?php session_start();
    if (!isset($_SESSION['authenticated']))
    {
        //if the value was not set, you redirect the user to your login page
        header('Location https://www.example.com/login.php');
        exit;
    }
    else
    {
       //if the user did login, then you load the page normally
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度