tags:

views:

27

answers:

1

How do I post them to whatever page from here and how can I send these variables to several pages at the same time?

//catched those variables within the same page
$event = $_POST['event'];
$when = $_POST['eventdate'];
$where = $_POST['place'];
$name = $_POST['name'];
$tel = $_POST['tel'];
$email = $_POST['email'];
send $event, $when, $where, ... to("whateverurl1");//not the way
+3  A: 

POSTing data to an URL can be done with the curl extension, which allows one to send HTTP requests from PHP.

In your case, something like this might do the trick :

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'event' => $event, 
    'when' => $when, 
    // ... more here
));
$returned = curl_exec($ch);
curl_close($ch);

For more informations you might want to take a look at the manual page of curl_exec, and for more options (there are a lot of possible options !), see curl_setopt.


Here, the most important ones are :

  • CURLOPT_URL : to specify the URL to which you want to post your data
  • CURLOPT_POST : as you want to send an HTTP POST request -- and not GET, which is the default
  • CURLOPT_POSTFIELDS : to specify the data that you want to send


But note this will not send several queries in parallel -- maybe curl_multi_exec and the other curl_multi_* functions could help, there...

Pascal MARTIN
Ok but do I have to include something because:Fatal error: Call to undefined function curl_init()
Chris_45
Oh, so not cool :-( ;; that function not being defined means the curl extension is not installed/enabled on your server ;-( ;;; maybe, if enabled on your server, a solution would be to use `fopen` + a stream context to send an HTTP POST request (see the example #1 on http://www.php.net/manual/en/context.http.php ) ;; else, you'll have to go to a library that uses `fsockopen`...
Pascal MARTIN
Ok I guess this work if it's enabled, thanks or shouldn't I check you're answer guessing?
Chris_45