Solved

automatic URL relocation

Posted on 2008-10-10
4
278 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
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

821 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