Solved

redirection?

Posted on 2001-06-10
5
218 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

627 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