Using sendtohost for redirect

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • susb8383
    New Member
    • Feb 2007
    • 4

    Using sendtohost for redirect

    Hi,
    Very new at PHP...

    I'm trying to use sendtohost to do a redirection to another page, passing it post variables. I see a lot of forum posts elsewhere that say you can do this, but none of them have full examples.

    So, here are my very basic questions.

    If I have page1.php and I'm trying to redirect to page2.php, passing post variables, how exactly do I call the sendtohost function from page1, and how do I redirect?

    Not having an example, I did this:

    page1.php contains:

    <?php
    (send to host function)
    ?>
    <?php sendToHost('www .mydomain.com', 'post','/page2.php','utm _nooverride=1') ; ?>


    But I just get a blank page.

    So,
    1) Is this syntax correct for calling the function, or do I put the call to the function inside a body tag? Do I put the function inside a head tag, or just before any html tags?
    2) I was expecting to be redirected to my new page, but all I get is a blank screen. Is there something more I have to do to make the redirect happen?

    Thanks.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    In order to help you or make an educated guess, show us all code, especially the sendtohost function. Without the latter we cannot help you.

    And when you show code: show it within code or php tags, like stated in the Posting Guidelines at the top of this forum!

    Ronald :cool:

    Comment

    • susb8383
      New Member
      • Feb 2007
      • 4

      #3
      Code:
      <?php 
      /* sendToHost
       * ~~~~~~~~~~
       * Params:
       *   $host      - Just the hostname.  No http:// or
                        /path/to/file.html portions
       *   $method    - get or post, case-insensitive
       *   $path      - The /path/to/file.html part
       *   $data      - The query string, without initial question mark
       *   $useragent - If true, 'MSIE' will be sent as
                        the User-Agent (optional)
       *
       * Examples:
       *   sendToHost('www.google.com','get','/search','q=php_imlib');
       *   sendToHost('www.example.com','post','/some_script.cgi',
       *              'param=First+Param&second=Second+param');
       */
      
      function sendToHost($host,$method,$path,$data,$useragent=0)
      {
          // Supply a default method of GET if the one passed was empty
          if (empty($method)) {
              $method = 'GET';
          }
          $method = strtoupper($method);
          $fp = fsockopen($host, 80);
          if ($method == 'GET') {
              $path .= '?' . $data;
          }
          fputs($fp, "$method $path HTTP/1.1\r\n");
          fputs($fp, "Host: $host\r\n");
          fputs($fp,"Content-type: application/x-www-form- urlencoded\r\n");
          fputs($fp, "Content-length: " . strlen($data) . "\r\n");
          if ($useragent) {
              fputs($fp, "User-Agent: MSIE\r\n");
          }
          fputs($fp, "Connection: close\r\n\r\n");
          if ($method == 'POST') {
              fputs($fp, $data);
          }
      
          while (!feof($fp)) {
              $buf .= fgets($fp,128);
          }
          fclose($fp);
          return $buf;
      }
      ?>
      <?php sendToHost('www.squirrelfreebirding.com','post','/downloads/test.html','utm_nooverride=1'); ?>

      Comment

      Working...