ปัญหา file_get_contents กับ cookie

วันก่อนผมจำเป็นต้องใช้ function file_get_contents แต่ไม่สามารถ เรียกใช้หรือแสดง cookie ในหน้านั้นๆ ได้ นั่งมึน !-_- อยู่ตั้งนานกว่าจะหาวิธีได้
ก็จะเอามาให้เพื่อนๆ ดูกันด้วย เผื่อวันใด วัน หนึ่ง จำเป็นต้องได้ใช้กัน

  1. $opts = array(‘http’ => array(‘header’=> ‘Cookie: ‘ . $_SERVER[‘HTTP_COOKIE’]."\r\n"));
  2.  
  3. $context = stream_context_create($opts);
  4.  
  5. $contents = file_get_contents([string filename], false, $context);
  6.  
  7. print $contents;

วิธีนี้จะได้ค่า Cookie กลับมาด้วย ปกติถ้าเราใช้ file_get_contents() ก็จะได้แต่ contents มาเท่านั้น

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Comments »

 
  • deen says:

    ขอบคุณครับ จะเก็บไว้ใน สมองก่อน

  • nosedive says:

    ทำไมลองแล้วมันไม่ได้หว่า..

 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>