Solved

redirection?

Posted on 2001-06-10
5
216 Views
Last Modified: 2006-11-17
how to refirect control to other html page or other php script?
0
Comment
Question by:zastava101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Accepted Solution

by:
superschlonz earned 26 total points
ID: 6174859
I thought I have seen a PHP function which does what you want but I can't find
it anymore. So I wrote a little function which should do it:

<?php
function httpPassthru( $host, $port, $file )
{
     if( $port == "" )
     {
          $port = 80;
     }
     $sock = fsockopen( $host, $port );
     if( !$sock )
     {
          return -1;
     }
     fwrite( $sock, "GET " . $file . " HTTP/1.0\r\n" );
     fwrite( $sock, "User-Agent: PHP\r\n" );
     fwrite( $sock, "Connection: close\r\n" );
     fwrite( $sock, "Host: " . $host . ":" . $port . "\r\n" );
     fwrite( $sock, "\r\n" );
     $line = fgets( $sock, 1000 );
     while( $line != "\r\n" )
     {
          $line = fgets( $sock, 1000 );
     }
     fpassthru( $sock );
}
httpPassthru( "www.linux.org", 80, "/" );
?>

But some links can be broken if you redirect a page like this.
0
 
LVL 4

Expert Comment

by:ykf2000
ID: 6175029
hi try this:


<?
    header("Location: another_page.php");
?>
0
 
LVL 1

Expert Comment

by:fajr_n
ID: 6175666
you all above is right.
But if you need the currnet page not in history, the script can see below.

<?
function redirect($target)
{
  header ("Cache-Control: no-cache, must-revalidate");
  header ("Pragma: no-cache");
  header ("Location: $target");
}
?>

$target is your target file or target url

Goodluck
0
 
LVL 1

Expert Comment

by:Rajko
ID: 6195507
<?
header("Location: another_page.php");
exit;
?>

exit - stopped the follow code.
0
 

Expert Comment

by:meetyg
ID: 6200016
Yup, thats the way to do it:

<?
header("Location: http://www.mysite.com");
exit;
?>

but the location doesn't have to be a full URL, it can be any valid URL.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question