I'm trying to post data from my office to my web server. The web server is a single machine that hosts lots of domains - all using the same IP... i.e., if I ping the server (hero.com) it shows the same ip as if I ping my domain.
So when I assemble my header & use my domain name, php turns the domain name into an ip, making the location of the action script no longer valid.
Here's the code:
Code:
$host = "www.mydomain.com";
$hostport = 80;
$action = "/client/process.php";
$req .= "a bunch of stuff";
$header .= "POST $action HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ($host, $hostport, $errno, $errstr, 30);
if ($fp) {
fputs ($fp, $header . $req);
} else {
print"Couldn't connect to $host\n";
}
If I just go directly to the site with my browser, it works, but if I run the above php from a command line at my office, the server returns a 404 because it's trying to find the action based on hero.com.
The access logs look like so:
working:
<my ip> - - [10/Dec/2005:10:52:56 -0800] "GET /client/process.php HTTP/1.1" 200 17 mydomain.com "-" "Links (1.00pre12; Linux 2.4.27-2-686-smp i686; 80x24) (Debian pkg 0.99+1.00pre12-1)"
non working (php script)
<my ip> - - [10/Dec/2005:10:53:20 -0800] "POST /client/process.php HTTP/1.0" 404 282 207.151.19.45 "-" "-"
The later shows the ip of hero.com... If I
http://207.151.19.45 , I get the main hero.com page.
What do I need to do to make sure it uses mydomain.com instead of the ip? I've tried using the full webserver path to process.php in the above code, but it does not work.
edit: the above code does not print out any sort of error message, so it makes the connection to hero.com or mydomain.com fine, it just can't post the data because it can't find the action.