컬링 HTTP POST 요청을 발행 한 간단한 PHP 스크립트를 사용하여 리디렉션을 통해 사용자에게 데이터를 표시합니다. 내가 가진 문제는 둘 이상의 사람이 동시에 스크립트를 실행하면 한 사람이 성공적으로 실행되고 완료되지만 다른 사람에게는 실패합니다. 세션 또는 쿠키와 관련된 것으로 생각되지만 session_start()를 사용하지 않고 쿠키가 리디렉션되기 전에 지워집니다.PHP 스크립트를 동시에 실행하는 사용자
왜 이런 일이 발생하며 동시 사용자를 지원하도록 스크립트를 조정할 수 있습니까?
<?php
$params = "username=" . $username . "&password=" . $password . "&rememberusername=1";
$url = httpPost("http://www.mysite.com/", $params);
removeAC();
header(sprintf('Location: %s', $url));
exit;
function removeAC()
{
foreach ($_COOKIE as $name => $value)
{
setcookie($name, '', 1);
}
}
function httpPost($url, $params)
{
try {
//open connection
$ch = curl_init($url);
//set the url, number of POST vars, POST data
// curl_setopt($ch, CURLOPT_COOKIEJAR, "cookieFileName");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//execute post
$response = curl_exec($ch);
//print_r(get_headers($url));
//print_r(get_headers($url, 0));
//close connection
curl_close($ch);
return $response;
if (FALSE === $ch)
throw new Exception(curl_error($ch), curl_errno($ch));
// ...process $ch now
}
catch(Exception $e) {
trigger_error(sprintf(
'Curl failed with error #%d: %s',
$e->getCode(), $e->getMessage()),
E_USER_ERROR);
}
}
?>
요청마다 고유 한 쿠키 병 파일을 만드시겠습니까? –
'$ url = httpPost ("http://www.mysite.com/, $ params);' –