Solved

automatic URL relocation

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
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.
The viewer will learn how to dynamically set the form action using jQuery.
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…

717 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