Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何防止通常通过 ajax 加载的页面自行加载?例如,如果在 main.php 中,您通过 ajax "cart.php" 加载并将其解析为本地 div。当用户尝试直接加载cart.php时,是否有可能将用户重定向到main.php?
--comment: javascript 不是一个选项
您可以检测页面是否通过 ajax 加载,如下所示:
if(strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') { /* special ajax here */ header("Location: http://www.example.com/main.php"); }