Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从另一个PHP脚本访问PHP cookie_Php_Cookies - Fatal编程技术网

从另一个PHP脚本访问PHP cookie

从另一个PHP脚本访问PHP cookie,php,cookies,Php,Cookies,我从另一个php脚本访问cookie变量时遇到问题。下面是代码片段 if (isset($remember) && $remember == 'on') { setcookie("username", $user, time() + (60 * 60 * 24 * 30)); setcookie("password", $pass, time() + (60 * 60 * 24 * 30)); } 如何从外部脚本访问cookie内容?谢谢当您从外部脚本发送

我从另一个php脚本访问cookie变量时遇到问题。下面是代码片段

if (isset($remember) && $remember == 'on') {

    setcookie("username", $user, time() + (60 * 60 * 24 * 30));
    setcookie("password", $pass, time() + (60 * 60 * 24 * 30));  
}

如何从外部脚本访问cookie内容?谢谢

当您从外部脚本发送HTTP请求时,
setcookie()
方法将向HTTP响应头追加一个名为
setcookie
的新头

Set-Cookie: username=myUserName
Set-Cookie: password=myUserPass
要读取这些cookie(实际上,我们只需要从响应中解析HTTP头),请使用以下内容:

file_get_contents("http://localhost:8080/test.php");

$receivedCookies = array();
$headerCount = count($http_response_header);

for($i = 0; $i < $headerCount; $i++){
    if(strpos($http_response_header[$i], "Set-Cookie") !== false){
        $receivedCookies[] = $http_response_header[$i];
    }
}

var_dump($receivedCookies);
文件获取内容(“http://localhost:8080/test.php");
$receivedCookies=array();
$headerCount=count($http\u response\u header);
对于($i=0;$i<$headerCount;$i++){
if(strpos($http\u response\u头[$i],“Set Cookie”)!==false){
$receivedCookies[]=$http_响应_头[$i];
}
}
var_dump($ReceivedOkies);

不要在cookies中传递密码,因为这非常不安全。你只是把钥匙给了这个用户!查看
$\u COOKIE
数组。所有cookie都会传递给所有脚本。假设他们没有超时