douqiao5543 2014-02-20 03:10
浏览 44

php通过静态html页面访问检查

I want to restrict access for users to their specific data. The site is all static html with a minimum of php to check if a user has permission. The url format is somesite.tld/public_html/english/user/1/account_overview.php?id=1 The site is available in some languages. the 'english' part of the url will change according to chosen language (french, german, dutch, ...). The 'english' part is a folder in public_html. The 'user' part is a folder in 'english' and the '1' is folder in 'user'.

I have a $_SESSION['userid']. At this moment the php script checks if the $_GET['id'] exists and if $_GET['id'] is equal to the $_SESSION['userid'] but just changing the url to somesite.tld/public_html/english/user/2/account_overview.php?id=1 does not limit the access to the '2' folder if you are logged in with userid = 1.

how can I stop displaying the data when someone modifies the url manually ?

  • 写回答

2条回答 默认 最新

  • douxin2003 2014-02-20 03:17
    关注

    I would recommend that you avoid this altogether. Rather than using a $_GET variable to determine if the user has permissions to view the account, why not just use one PHP retrieval script that uses the session variable to get the user's account.

    It would go something like this:

    You have all of the account files stored in a directory that is read protected, like:

    /accounts/
    

    Then in your PHP file:

    session_start();
    include($_SERVER["DOCUMENT_ROOT"]."/accounts/".$_SESSION["userid"].".html");
    

    This will avoid the issue altogether. By read-protecting the directory to all except the PHP user, you can prevent people from accessing the files without being logged in. Then you don't have any loose $_GET variables and all of the account info is secure.

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?