0

I have an ajax.php file to which all of my ajax calls point with an extra parameter of the script the current call demands to execute. My problem is that I want to limit some scripts to being executed by specific pages only, say for example sendComment.php should only be called from www.mysite.com/user/{any user}.

What I have done is put this code on top of every script that I want to limit:

if(strstr($_SERVER['HTTP_REFERRER'],'mysite.com/{page_allowed_to_exec_script}'){
    Then do stuff here
}

But what I've come to notice is that not all browsers support the HTTP_REFERRER ( I might have spelled that incorrectly, I'm writing this by memory ), and as well as not being cross-browser it's also a pain in the butt having to hardcode this stuff in all of the files and is going to be an even bigger pain when it comes to changing stuff.. I'm looking for a way I can possibly have all the scripts in an array with all the pages that are able to execute them, and perform a check in the ajax.php file at start.

Does anyone have any idea how this can be achieved?

4

1 回答 1

1

甚至所有浏览器都可能不会发送“referer”,因为某种“代理”、“防火墙”或“安全”套件会将其剥离甚至更改。因此您可以信任它。

如果您控制引荐页面,您可以使用会话、cookie 或 URL 来传递信息(如果您认为这些信息非常重要)。如果它绝对重要,那么您唯一的选择就是会话。其他两个可以很容易地删除。

于 2013-06-22T12:07:30.363 回答