LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-11-2005, 10:16 AM   #1
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Rep: Reputation: 15
is this php automatic form submit post wriiten correctly? fsock error..


I have a form on my website that creates cookies in the header when the page loads. I am attempting to mimic a form post.

I get the following 2 errors when tring to simulate the post:

Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/html/postit2.php on line 60

Warning: fsockopen(): unable to connect to http::80 in /var/www/html/postit2.php on line 60
Error 0 Success

The initial code on my page with the data I want to automatically send to my form is

Code:
 

include("postit2.php");

require_once "HTTP/Request.php";

$req =& new HTTP_Request(" http://www.abc.com/page.php");


$data["dbType"] = "mysql";
  $data["dbHost"] = "localhost";
  $data["dbUser"] = "xxx";
  $data["dbPass"] = "letmein";
  $data["dbName"] = "me";

  $result = post_it2($data, " http://www.abc.com/page.php");

  if (isset($result["errno"])) { 
    $errno = $result["errno"]; 
    $errstr = $result["errstr"]; 
    echo "<B>Error $errno</B> $errstr"; 
    exit; 
  } else { 

    for($i=0;$i< count($result); $i++) echo $result[$i]; 

  } 

?>
the php file with the function info that should submit the form is:

Code:
<?php

function post_it2($data, $URL) {

//  Strip http:// from the URL if present
    $URL = ereg_replace("^http://", "", $URL);

//  Separate into Host and URI
    $Host = substr($URL, 0, strpos($URL, "/"));
    $URI = strstr($URL, "/");

//  Form up the request body
    $ReqBody = "";
    while (list($key, $val) = each($data)) {
      if ($ReqBody) $ReqBody.= "&";
      $ReqBody.= $key."=".urlencode($val);
    }
    $ContentLength = strlen($ReqBody);

//  Generate the request header
    $ReqHeader =
      "POST $URI HTTP/1.0\n".
      "Host: $Host\n".
      "User-Agent: PostIt\n".
      "Content-Type: application/x-www-form-urlencoded\n".
      "Content-Length: $ContentLength\n\n".
      "$ReqBody\n";

//     echo $ReqHeader;


//  Open the connection to the host
    $socket = fsockopen($Host, 80, &$errno, &$errstr);
    if (!$socket) {
      $Result["errno"] = $errno;
      $Result["errstr"] = $errstr;
      return $Result;
    }
    $idx = 0;
    fputs($socket, $ReqHeader);
    while (!feof($socket) && $Result[$idx-1] != "0\r\n") {
    if (substr($Result[$idx-1], 0, 2) == "0\r\n") echo "The End:".strlen($Result[$idx-1]);
      $Result[$idx++] = fgets($socket, 128);
    }
    return $Result;
  }
?>
why do I get the two errors above? Is it because I am suppose to send the cookies back in the form somehow?

The name of the cookie is PHPSESSID I believe

I have read an article on zend dot com about mimicking submission posts and am still lost. Any help given would be greatly appreciated.

Thanks

http://www.zend.com/zend/spotlight/m...ynamicwebpages
 
Old 05-11-2005, 10:24 AM   #2
rylan76
Senior Member
 
Registered: Apr 2004
Location: Potchefstroom, South Africa
Distribution: Fedora 17 - 3.3.4-5.fc17.x86_64
Posts: 1,552

Rep: Reputation: 103Reputation: 103
Don't know about all your code, but I get the same two errors when I try to run my SMS sending script on my local machine, instead of my online server. The SMS code used the file() function, and this is that complains about the socket and unknown protocol, at least on my development machine.

My online machine is configured and maintained for me by Hetzner Africa. The thing is, my development machine can be considered "incorrectly" configured for running my SMS sending code - while the online machine is "correctly" configured.

Since I get the exact same errors you get on my development machine (but NOT my online machine) it -might- mean that there is nothing wrong with your code, but your machine configuration as regards PHP is incorrect for what you are trying to do.

Or the machine you are trying the script on must be connected to the internet (my development machine isn't, and that is why it gets the same two errors you get) while my online machine is (which is why it works).

Hope this helps a bit and doesn't just confuse you more...
 
  


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
PHP form takes forever to submit newuser455 Programming 3 06-09-2005 04:17 AM
submit a form with javascript djgerbavore Programming 6 06-01-2005 02:46 PM
PHP:Unable to post variables from html form to mysql database vikram_cvk Linux - Software 1 09-29-2004 03:01 PM
PHP and HTML Form Post Savahn Programming 12 06-30-2004 03:15 PM
Post information not coming through PHP form. m3kgt Programming 5 04-02-2004 01:42 PM

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

All times are GMT -5. The time now is 01:13 PM.

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