php判断正常访问和外部访问的示例
程序员文章站
2023-11-26 15:11:28
php判断正常访问和外部访问 复制代码 代码如下:
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">