whitsey Posted April 13, 2010 Share Posted April 13, 2010 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 page, the only difference is that I don't want to initiate it from the client, I want to automate it on job entry (therefore it will send an email with the same format and structure every time 1) on entry of job and 2) if you call up job and resend) PHP Code: This is all I use: file_get_contents($base_url.'admin/send.email.php?order_id='.$order_id) HOWEVER...When I call the page this way, the $_SESSION array I am working with is empty. I assume this is 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 a new page? It makes sense that the new call doesn't have access to the existing session... So, I have now tried to send the cookies across but I am having more issues: I just want to call this page to send an email... Should I persist with figuring out how to pass the $_session or (as the method below isn't working) or is there an easier way (without re-writing all the code) When I try to pass the session cookie, I 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.email.php?order_id='.order_id, false, $context); YET, the URL works fine if I call it without this: (It just doesn't let me access session) $result = file_get_contents($base_url.'admin/send.email.php?order_id='.$order_id); The error I'm getting indicates that it can't connect to the server but that is clearly not the case because the second call proves the connection is not a problem!!! Link to comment https://forums.phpfreaks.com/topic/198350-accessing-_session-when-using-file_get_contents/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.