开发者

How to deny anyone from accessing from the URL?

It Might be easy ... bu开发者_如何学编程t what to write in .htaccess file to prevent anyone to access specific page from the URL

Like

http://example.com?id=12

user may change the id value from the url to access another page so i want to prevent that ...


I don't think you can do that using the .htaccess file. You would be better off using sessions and/or cookies to control access to restricted content.


I would write some code PHP to handle this, and not an .htaccess rule.

Something like this would work:

if(array_key_exists('id', $_GET) {
  if($_GET['id'] === 12)
    die("Cannot view this page");
}


Do some research on authentication and access control in PHP. It is a bit complicated for somebody to be able to give you a code snippet or short answer here.

If you then have specific problems with your code to implement what you have learned then this is the place to come for help.


you can't because the user can see the id and type the same thing to other tab and access, there is a method to prevent from editing, but as far as it goes for not accessing, create a php file and block every id=12 requests, or whatever request you want to block.


Agreed that this is more of a server side problem if the user should be allowed to access particular pages. It could get very complicated with .htaccess rules.

Why not try something like this:

<?php
  $allow = array(12, 13); // values that you want to allow access to
  if ( in_array($_GET['id'], $allow) !== true ) {
    die("Access denied.");
  }
?>


This might do the trick

RewriteEngine on
RewriteRule ^/?id=12$ /denied [L]

It'd at least prevent the script from being invoked if that query parameter is present, which is slightly more secure than allowing the hit to actually get to the script.


You would do this via PHP:

<?php
$denied = array(12);
if (isset($_GET['id']) && in_array($_GET['id'], $denied)) {
    header('HTTP/1.1 403 Forbidden');
    exit;
}
?>


you can use the post method instead, so the user is not aware what variable is passed between files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜