忍者ブログ
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。



2024/04/29 13:16 |
ZF1.10 :file_get_contentsでZend_Http_Cookie
前回Zend_Http_Cookieでcookieを簡単に取得しましたが、file_get_contents()で実行することも可能です。

zend_http5.php
<?php
	
	$zend_http1='http://localhost/zend_http1.php';
	$zend_http2='http://localhost/zend_http2.php';

	//取得
		$file = file_get_contents($zend_http1);
	
	//HTTPレスポンスヘッダは$http_response_headerに入ってくる
		foreach($http_response_header as $key=>$val){
			//cookieを取得
			if(strpos($val, 'Set-Cookie:')!==false){
				$cookie_val = str_replace('Set-Cookie:', '', $val);;
				break;
			}
		}
	
	//ストリームコンテキスト作成
		$opts = array(
			'http'=>array(
				'method'=>'POST',
				'header'=>'Cookie:'.$cookie_val."\r\n"
			)
		);
		$context = stream_context_create($opts);

	//ストリームコンテキストを使用してfile_get_contents
		$res = file_get_contents($zend_http2, false, $context);

さほど難しくないといえばそのとおりなのですが、$http_response_headerとかstream_context_create()とかfile_get_contents()の第三引数とか、普通は使わないような関数を使わないといけないので少々面倒です。
あとcookieが無かった場合とか何も考えてない作りなのでそこらへんもどうにかする必要があります。


Zend_Http_Cookieまったく関係ないな。

 

PR


2010/10/11 21:21 | Comments(0) | TrackBack() | PHP

トラックバック

トラックバックURL:

コメント

コメントを投稿する






Vodafone絵文字 i-mode絵文字 Ezweb絵文字 (絵文字)



<<コメントSPAM投稿システム見つけた | HOME | 買ったものリスト 2010/10/10>>
忍者ブログ[PR]