php判断正常访问和外部访问的示例
(编辑:jimmy 日期: 2024/11/19 浏览:3 次 )
php判断正常访问和外部访问
复制代码 代码如下:
<?php
session_start();
if(isset($_POST['check'])&&!empty($_POST['name'])){
if($_POST['check'] == $_SESSION['check']){
echo "正常访问";
}else{
echo "外部访问";
}
}
$token = md5(uniqid(rand(),true));
$_SESSION['check'] = $token;
?>
<form method="post" action="">
<input type="text" name="name"/>
<input type="text" name="check" value="<?=$token;?>">
<input type="submit">
复制代码 代码如下:
<?php
session_start();
if(isset($_POST['check'])&&!empty($_POST['name'])){
if($_POST['check'] == $_SESSION['check']){
echo "正常访问";
}else{
echo "外部访问";
}
}
$token = md5(uniqid(rand(),true));
$_SESSION['check'] = $token;
?>
<form method="post" action="">
<input type="text" name="name"/>
<input type="text" name="check" value="<?=$token;?>">
<input type="submit">
下一篇:php利用单例模式实现日志处理类库