我正在尝试将自定义标头发送到同一文件(在php中使用curl)
这是文件(test.php):
@session_start();
@session_unset(($_SESSION['token']));
if(empty($_SESSION['token'])){
$_SESSION['token'] = bin2hex(openssl_random_pseudo_bytes(16));
}
$token = $_SESSION['token'];
$uri = 'http://localhost/test.php'; // the samw file
$ch = curl_init($uri);
curl_setopt_array($ch, array(
CURLOPT_HTTPHEADER => array('X-Simple-Protection: '.$token.''),
CURLOPT_RETURNTRANSFER =>true,
CURLOPT_VERBOSE => 1));
$out = curl_exec($ch);
curl_close($ch);
if($_SERVER['HTTP_X_SIMPLE_PROTECTION'] == $token){
echo "token : ".token;
}else{
echo "error";
}
运行文件时,出现以下错误:
注意:未定义索引:HTTP_X_SIMPLE_PROTECTION C:\ Users \ me \ Desktop \ xampp \ htdocs \ test.php在第24行出现错误
我尝试发送到文件本身,这可能吗?