PHP 判断请求来源
程序员文章站
2022-03-11 23:05:31
...
<?php header('Content-Type: text/html; charset=utf-8'); define("WEBSITE", "http://onestopweb.iteye.com"); if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['fdata'])){ sourceJudgment(); echo $_POST["website"]; exit; } //来源判断 function sourceJudgment(){ if (strpos($_SERVER['HTTP_REFERER'], WEBSITE)===false) { header('Location:'.WEBSITE.'/index.php?f='.$_SERVER['HTTP_REFERER']); exit; } } ?> <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>PHP 判断请求来源</title> </head> <body> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <input type="text" name="website" value="" placeholder="请输入网址"> <input type="submit" name="fdata" value="提交"> </form> </body>
效果图:
上一篇: PHP之Redis扩展从安装到使用
下一篇: 学php能找到工作吗?