473,387 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.
Feb 28 '07 #1
2 4353
ronverdonk
4,258 Expert 4TB
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:
Feb 28 '07 #2
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. /* sendToHost
  3.  * ~~~~~~~~~~
  4.  * Params:
  5.  *   $host      - Just the hostname.  No http:// or
  6.                   /path/to/file.html portions
  7.  *   $method    - get or post, case-insensitive
  8.  *   $path      - The /path/to/file.html part
  9.  *   $data      - The query string, without initial question mark
  10.  *   $useragent - If true, 'MSIE' will be sent as
  11.                   the User-Agent (optional)
  12.  *
  13.  * Examples:
  14.  *   sendToHost('www.google.com','get','/search','q=php_imlib');
  15.  *   sendToHost('www.example.com','post','/some_script.cgi',
  16.  *              'param=First+Param&second=Second+param');
  17.  */
  18.  
  19. function sendToHost($host,$method,$path,$data,$useragent=0)
  20. {
  21.     // Supply a default method of GET if the one passed was empty
  22.     if (empty($method)) {
  23.         $method = 'GET';
  24.     }
  25.     $method = strtoupper($method);
  26.     $fp = fsockopen($host, 80);
  27.     if ($method == 'GET') {
  28.         $path .= '?' . $data;
  29.     }
  30.     fputs($fp, "$method $path HTTP/1.1\r\n");
  31.     fputs($fp, "Host: $host\r\n");
  32.     fputs($fp,"Content-type: application/x-www-form- urlencoded\r\n");
  33.     fputs($fp, "Content-length: " . strlen($data) . "\r\n");
  34.     if ($useragent) {
  35.         fputs($fp, "User-Agent: MSIE\r\n");
  36.     }
  37.     fputs($fp, "Connection: close\r\n\r\n");
  38.     if ($method == 'POST') {
  39.         fputs($fp, $data);
  40.     }
  41.  
  42.     while (!feof($fp)) {
  43.         $buf .= fgets($fp,128);
  44.     }
  45.     fclose($fp);
  46.     return $buf;
  47. }
  48. ?>
  49. <?php sendToHost('www.squirrelfreebirding.com','post','/downloads/test.html','utm_nooverride=1'); ?>
  50.  
Mar 1 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: JDJones | last post by:
We are trying to set up a PHP page to handle server requests for individual web pages that we are moving to a new server. The part that complicates this procedure is that the files will not be...
2
by: vishal | last post by:
hello friends i have one php script which generates html page containing form. what i want is submit this form using php script. pls give me some idea that how can i submit form using php...
4
by: zborisau | last post by:
Hey good people, I've been given a problem to solve recently - and stuck with the solution for a good 4 days already. i have a link which leads to popup window. the purpose of that popup...
0
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
3
by: Pooja Renukdas | last post by:
Hello, I have this web site where only two pages have to be secure pages and I need to call them using https, but since I have my development server and my production web server, I dont want to...
10
by: Anthony Williams | last post by:
Hi gang, This one looks like a bug :o( As you may or may not know, setting session management in web.config to use cookieless sessions causes the ASP.NET runtime to munge a session ID into...
11
by: youngster94 | last post by:
Hey all, I've written a VB.Net app that creates picture badges complete with barcodes. The problem is that the barcode quality is not good enough to be read by scanners. I'm using the...
1
by: rouellette | last post by:
Is it possible to redirect to another page in your application from the start page BEFORE the user has been authenticated if you're using FORMS authentication? I can't seem to get it to work. ...
3
by: jasonheath.net | last post by:
I apologize in advance for the length of this post. I wanted to get as much detail as possible in here. We have 1 web app that contains the functionality to do some single sign-on logic. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.