Solved

automatic URL relocation

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
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.

813 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

12 Experts available now in Live!

Get 1:1 Help Now