Jump to content

fsockopen() only opens one out of all the domains on my server. Need Urgent Help


ayanex10

Recommended Posts

[color=red]====================================================
<?php

$req = '[email protected]&Name=Ebun&[email protected]';


$header = "POST /SendMessage.php 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 ('www.xyz.com', 80);

if (!$fp) {echo "error in connection"; die(); }

fputs ($fp, $header . $req);

$res = '';
$headerdone = false;

while (!feof($fp)) {
$line = fgets ($fp, 1024);

if (strcmp($line, "\r\n") == 0) {
// read the header
$headerdone = true;
}
else if ($headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}

echo $res; die();
?>
====================================================[/color]



The code above is to send an HTTP POST data to a file on my server. It works fine and very well but I just have a problem with fsockopen.

I have a server that has many domain names registered under it. The above example works fine but if I change the host name to another domain on my server, it will always bounce back to the domain above (xyz.com).

I discovered that all the domain names on my server resolve to only one IP address and this IP address in turn resolves to only one hostname (xyz.com).

So what I need is a way to tell fsockopen to open exactly the domain name I specify as my host name and not the default domain name on my server. Remember I have many domain names on my server.

Please is there a way to get around this. Please I need help as urgent as possible

My head is craking over here.
Try fsockopen('http://www.domain.com').

The problem is most likely that the Host: header, which tells a webserver which site to server, is invalid.  The server then falls back to serving the default site.  If none of this works, try using the CURL functions.

http://sg.php.net/manual/en/ref.curl.php

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.