invincible_virus Posted October 5, 2008 Share Posted October 5, 2008 Hi, My requirement is to initiate a HTTP post request using php code. There are two ways I know, both having their limitations - 1. Doing header("Location:./redirected.php"); It will redirect the browser to redirected.php, but there is no way I can specify POST variables. 2. Using cURL $redirect_handler = curl_init(); curl_setopt($redirect_handler, CURLOPT_URL, SITE_ROOT."redirected.php"); curl_setopt($redirect_handler, CURLOPT_RETURNTRANSFER, 0); curl_setopt($redirect_handler, CURLOPT_TIMEOUT, 60); curl_setopt($redirect_handler, CURLOPT_POST, 1); curl_setopt($redirect_handler, CURLOPT_POSTFIELDS, $post_fields_array); curl_exec($redirect_handler); if (curl_errno($redirect_handler)) { print "Error: " . curl_error($redirect_handler); } curl_close($redirect_handler); This one is pretty good as I can redirect the browser to redirected.php with some POST data. But, this will create a new session and I loose data set in the session. Is there any way using which I can preserve both POST & SESSION variables data ? Link to comment https://forums.phpfreaks.com/topic/127125-http-post-request-from-php/ Share on other sites More sharing options...
R0bb0b Posted October 5, 2008 Share Posted October 5, 2008 You could pass the sessID Link to comment https://forums.phpfreaks.com/topic/127125-http-post-request-from-php/#findComment-657584 Share on other sites More sharing options...
invincible_virus Posted October 5, 2008 Author Share Posted October 5, 2008 I've seen the documentation of curl_init() and it says - Initializes a new session and return a cURL handle for use with the curl_setopt(), curl_exec(), and curl_close() functions. There is no option to set the session id. can you please tell me where can I pass that? Thanks... Link to comment https://forums.phpfreaks.com/topic/127125-http-post-request-from-php/#findComment-657589 Share on other sites More sharing options...
R0bb0b Posted October 5, 2008 Share Posted October 5, 2008 You should be able to use this: http://us.php.net/manual/en/function.session-id.php Curl may create a new session but you can reset it with this function. You can also get it to post with curl with this function as well. Link to comment https://forums.phpfreaks.com/topic/127125-http-post-request-from-php/#findComment-657595 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.