目的
現物
<?php $headers = getallheaders(); $domain = "ここにアクセス先ドメインを記述"; $postAddress=htmlspecialchars(@$_POST['postAddress']) ;//パスはここで渡して。POSTのみ対応 $url = 'https://'.$domain.'/'.$postAddress; $COOKIE="COOKIE"; $jsession=htmlspecialchars(@$_COOKIE['JSESSIONID']) ; $path = realpath( "." )."/cookie"; $cookiefile=!is_null($jsession)?$path."/".$COOKIE.$jsession:$path."/".$COOKIE; $fp = fopen($cookiefile, "w"); fclose($fp); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); curl_setopt($ch, CURLOPT_COOKIE,"JSESSIONID=".$jsession."; "); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); curl_setopt($ch, CURLOPT_SSLVERSION, 3); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_USERAGENT, $headers["User-Agent"]); curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST); curl_setopt($ch, CURLOPT_ENCODING, $headers["Accept-Encoding"]); $data=curl_exec($ch); curl_close($ch); $fp2 = fopen($cookiefile, "r"); while (!feof($fp2)) { $columns=preg_split('/\t|\r\n|\r|\n/', fgets($fp2)); if($domain==$columns[0] && $columns[5]=="JSESSIONID"){ $jsession = preg_replace("/\r\n|\r|\n/","",$columns[6]); } } fclose($fp2); $newCookieFileName=$path."/".$COOKIE.$jsession;//JSESSION単位で存在できるように if (file_exists($newCookieFileName) && is_dir($newCookieFileName)) { echo "$newCookieFileName はディレクトリです"; }else{ copy( $cookiefile, $newCookieFileName); if ( !unlink($cookiefile)) {echo "ファイル削除失敗!!";} } $timeout = time() + 30 * 86400;//時間は適当 setcookie("JSESSIONID",$jsession,$timeout,'/',$_SERVER["SERVER_NAME"]);//クライアントへクッキー渡し print mb_convert_encoding($data, 'utf8', 'sjis-win'); ?>
以上!。