Solved

automatic URL relocation

Posted on 2008-10-10
4
281 Views
Last Modified: 2013-12-13
Hi all,

Whilst coding with ColdFusion I have become used to using a relocate function that takes one argument, an URL of the page to relocate to. Using this function allowed for the execution of a script to jump to the start of a specified URL meaning a page could be made to automatically load another page, as if a link had been clicked by the user.

What is the equivalent in PHP I've looked all over and must be searching for the wrong function name. Can anyone help?

Cheers
0
Comment
[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
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 125 total points
ID: 22687333
There is no special function in PHP for this, but it can be done using a http Location header, created with the PHP header() function. You can not have any output to the page before this function is called.
function redirect($url) {
  header('Location: '.$url);
}

Open in new window

0
 
LVL 1

Assisted Solution

by:jarospirit
jarospirit earned 250 total points
ID: 22687505
header, would redirect the user to a new page, but that is a URL redirection, if I understand the question correctly what you want its to load another page?
0
 
LVL 1

Assisted Solution

by:jarospirit
jarospirit earned 250 total points
ID: 22687528
header, would redirect the user to a new page, but that is a URL redirection, if I understand the question correctly what you want it's to include a script from another page?

please load the ColdFusion function or your script to understate better

thank you.
0
 
LVL 29

Assisted Solution

by:fibo
fibo earned 125 total points
ID: 22693362
Just a note "en passant": for 'header()' to work, it is important that no html code has been sent previously by the page.
A common problem is when there are spaces or empty lines before the <?php tag.
There should be none if you expect header() to work fine.
0

Featured Post

Industry Leaders: 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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 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