note 91809 added to curl.examples

From: Date: Fri, 26 Jun 2009 11:46:22 +0000
Subject: note 91809 added to curl.examples
Groups: php.notes 
Request: Send a blank email to php-notes+get-157524@lists.php.net to get a copy of this message
If you want to write a sort of php wrapper to include the results of another http(s) request maybe pointing to a totally different site or just different code (mod_perl with HTML::Mason, in my case) into a php based layout, and just pass-thru all GET and POST variables to the sub-request, the following snippet can be used. Note there is no error handling, so this is subject to the underlying application. <?php $ch = curl_init($sub_req_url); $encoded = ''; // include GET as well as POST variables; your needs may vary. foreach($_GET as $name => $value) { $encoded .= urlencode($name).'='.urlencode($value).'&'; } foreach($_POST as $name => $value) { $encoded .= urlencode($name).'='.urlencode($value).'&'; } // chop off last ampersand $encoded = substr($encoded, 0, strlen($encoded)-1); curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_exec($ch); curl_close($ch); ?> ---- Server IP: 81.223.48.75 Probable Submitter: 62.178.179.12 ---- Manual Page -- http://www.php.net/manual/en/curl.examples.php Edit -- https://master.php.net/note/edit/91809 Del: integrated -- https://master.php.net/note/delete/91809/integrated Del: useless -- https://master.php.net/note/delete/91809/useless Del: bad code -- https://master.php.net/note/delete/91809/bad+code Del: spam -- https://master.php.net/note/delete/91809/spam Del: non-english -- https://master.php.net/note/delete/91809/non-english Del: in docs -- https://master.php.net/note/delete/91809/in+docs Del: other reasons-- https://master.php.net/note/delete/91809 Reject -- https://master.php.net/note/reject/91809 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157524) next »