LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-10-2005, 01:00 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
PHP - fsocket open to shared ip host not working


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.

Last edited by BrianK; 12-10-2005 at 01:05 PM.
 
Old 12-10-2005, 05:19 PM   #2
Spudley
Member
 
Registered: Mar 2003
Location: Berkshire, England.
Distribution: SuSE 10.0
Posts: 299

Rep: Reputation: 32
You need to use HTTP/1.1 instead of 1.0.

HTTP 1.0 does not support domain mapping -- ie having multiple domains on a single IP address; this was the key difference in 1.1. There were other differences, of course, but that was the main one you'd notice, and I'd be willing to bet it's what's causing the problem here.

For more info, see this document (the section entitled "Internet address conservation" is the bit that's relevant)

Hope that helps.
 
Old 12-11-2005, 05:28 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by Spudley
You need to use HTTP/1.1 instead of 1.0.

HTTP 1.0 does not support domain mapping -- ie having multiple domains on a single IP address; this was the key difference in 1.1. There were other differences, of course, but that was the main one you'd notice, and I'd be willing to bet it's what's causing the problem here.

For more info, see this document (the section entitled "Internet address conservation" is the bit that's relevant)

Hope that helps.
Interesting. I didn't know about the difference between 1.0 & 1.1. Thanks.

Unfortunately, it didn't help - the same thing happens using HTTP/1.1 in the header... the access log shows it returned a 404 & appears to still have tried to use the ip rather than the domain name... which actually makes sense because the header doesn't come into play until after I've made the socket connection.

I've worked around it by using a get method rather than post & send all the info through the URL. I'd rather not do it that way, so if any other ideas come up, I'd be happy to hear them.

Last edited by BrianK; 12-11-2005 at 05:29 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
error while loading shared libraries: libstdc++.so.5: cannot open shared object file: Franziss Linux - Newbie 10 06-28-2010 05:47 AM
Urgent !!! rpm: error while loading shared libraries: libelf.so.1: cannot open shared tinaa Linux - Software 5 12-02-2008 03:19 PM
security considerations with 777 on shared host? learnfast Linux - Newbie 3 08-13-2005 01:59 PM
error while loading shared libraries: libdb-4.1.so: cannot open shared object file putquery8581 Linux - Software 1 10-01-2004 07:03 AM
mplayer: error while loading shared libraries: libdvdread.so.3: cannot open shared ob Bruce Hill Slackware 6 12-11-2003 08:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration