accessing $_SESSION when using file_get_contents in PHP

Posted by hairdresser-101 on Stack Overflow See other posts from Stack Overflow or by hairdresser-101
Published on 2010-04-13T06:00:56Z Indexed on 2010/04/13 6:02 UTC
Read the original article Hit count: 502

I am basic - intermediate developer using php and am a little stumped as to what I have found.

I need some help in understanding how to alleviate this issue:

I have a page called send.email.php which sends an email - pretty simple stuff - I pass an order id, it creates job request and sends it out. This works fine when used in the context I developed it (Use javascript to make an AJAX call to the URL and pass the order_id as a query parameter)

I am now trying to reuse the exact same page in another application however I am calling it using php file_get_contents($base_url.'admin/send.email.php?order_id='.$order_id). When I call the page this way, the $_SESSION array is empty isempty() = 1.

Is this because I am initiating a new session using file_get_contents and the values I stored in the $_SESSION on login are not available to me within there?

Any help?
Thanks

© Stack Overflow or respective owner

accessing $_SESSION when using file_get_contents in PHP

Posted by hairdresser-101 on Stack Overflow See other posts from Stack Overflow or by hairdresser-101
Published on 2010-04-13T07:11:58Z Indexed on 2010/04/13 7:12 UTC
Read the original article Hit count: 502

Filed under:
|
|

I have a page called send.email.php which sends an email - pretty simple stuff - I pass an order id, it creates job request and sends it out. This works fine when used in the context I developed it (Use javascript to make an AJAX call to the URL and pass the order_id as a query parameter)

I am now trying to reuse the exact same page in another application however I am calling it using php file_get_contents($base_url.'admin/send.email.php?order_id='.$order_id). When I call the page this way, the $_SESSION array is empty isempty() = 1.

Is this because I am initiating a new session using file_get_contents and the values I stored in the $_SESSION on login are not available to me within there?

--> Thanks for the feedback. It makes sense that the new call doesn't have access to the existing session...

New problem though:

I now get: failed to open stream: HTTP request failed! When trying to execute:

$opts = array('http' => array('header'=> 'Cookie: ' . $_SERVER['HTTP_COOKIE']."\r\n"));
$context = stream_context_create($opts);
$contents = file_get_contents($base_url.'admin/send.sms.php?order_id='.order_id, false, $context);

YET, the URL works fine if I call it as: (It just doesn't let me access session)

$result file_get_contents($base_url.'admin/send.sms.php?order_id='.$order_id);

© Stack Overflow or respective owner

Related posts about php

Related posts about file-get-contents