Solved

redirection?

Posted on 2001-06-10
5
208 Views
Last Modified: 2006-11-17
how to refirect control to other html page or other php script?
0
Comment
Question by:zastava101
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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now