Jump to content

HTTP Post request from PHP


invincible_virus

Recommended Posts

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

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.