views:

187

answers:

4

Simple Script

<?php
$host = "mysite.com";
$path = "/test.php";
$data = "drivingMeCrazy";
$data = urlencode($data);

header("POST $path HTTP/1.1\r\n" );
header("Host: $host\r\n" );
header("Content-type: application/x-www-form-urlencoded; charset=utf-8\r\n" );
header("Content-length: " . strlen($data) . "\r\n" );
header("Connection: close\r\n\r\n" );
header($data);
?>

When running this, my server just gives me Internal Error. All I need to do is just....POST. Nothing else. I don't need a response or anything.

Following Specs from here: http://www.sixapart.com/pronet/docs/trackback_spec.

+2  A: 

The header function is for setting the header for the response. If you want to make a request to another server, try cURL.

Gumbo
Thanks for fixing my post. How do you add code on here though...seriously? :) I know there is the code button, but I hate having the blank, invisible spaces I'm suppose to type in between. Is there a way to use tags like [code] or something? that will format it properly and give you a way to see where you are actually pasting code to.
Senica Gonzalez
@Senica Prefix each line of code with 4 spaces, or use back ticks (the ~ key) to markup `code` inline. Edit your post and you can see how others have improved the markup.
meagar
+1  A: 

You cannot use header() to send data to a 3rd party server. header() simply sends header information to the client making the request to your webserver.

Look into the cURL library for initiating requests to 3rd parties from your server-side PHP:

http://ca.php.net/manual/en/book.curl.php

I cannot vouch for this library, but it appears to be a freely available implementation of Trackbacks for PHP:

http://sourceforge.net/projects/phptrackback/

meagar
+2  A: 

You're looking for something like this:

$process = curl_init($host);                                                                         
curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', $additionalHeaders));  //<-- update to reflect your content-type
curl_setopt($process, CURLOPT_HEADER, 1);                                                                           
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password); // <-- you probably don't need that                                                
curl_setopt($process, CURLOPT_TIMEOUT, 30);                                                                         
curl_setopt($process, CURLOPT_POST, 1);                                                                             
curl_setopt($process, CURLOPT_POSTFIELDS, $payloadName);                                                            
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);                                                                
$return = curl_exec($process);  
Mr-sk
s/your/you're/i
meagar
Ok - fixed! wooooooooo
Mr-sk
A: 

Found an answer I was looking for here:

http://bytes.com/topic/php/answers/1211-doing-http-post

Curl would have worked. I just wanted to make this work on a different platform as well, so I wanted to find the most direct way. Thanks again.

Senica Gonzalez