PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old January 10th, 2003, 05:04 PM
Quantum Quantum is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Canada
Posts: 15 Quantum User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Does PHP support a Redirect function?

I am building a user login section that will redirect the user automatically to a web address stored in a database.
I have done this in ASP using Responce.Redirect and would like to know if PHP supports the same type of functionality.

Thanks.

Reply With Quote
  #2  
Old January 10th, 2003, 05:13 PM
corker corker is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 18 corker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Use the HEADER function:

$url = "http://www.someplace.com";
header("Location: $url");

You need to execute the header function before sending any other text to the browser.

Reply With Quote
  #3  
Old January 10th, 2003, 05:16 PM
Quantum Quantum is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Canada
Posts: 15 Quantum User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking

Thanks corker! I didn't realize it was going to be that simple.

Reply With Quote
  #4  
Old January 10th, 2003, 06:08 PM
kylie kylie is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 19 kylie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
if the headers are already outputted and you want to use the header redirect, place ob_start() at the very top of your page, to suppress the headers from being sent out.

Reply With Quote
  #5  
Old January 10th, 2003, 06:53 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
or use

Code:
<script language="javascript">
location.href="yourpage.php";
</script>
__________________
-- Jason

Reply With Quote
  #6  
Old January 10th, 2003, 06:57 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
oh, and if this is used in combination with for example an authentication system, you should do an exit() after the header call (if the headers are already sent or the browser ignores the location header, they'll be able to see the page if you don't call exit())

PHP Code:
<?php
header
('Location: blabla');
exit(
'Error: Header redirection failed.');
?>
__________________
Best Regards,
Håvard Lindset

Reply With Quote
  #7  
Old January 10th, 2003, 07:58 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
yes, good call Lindset. I found out about this just the other day,...lol I feel like a nUb, but thats what this is all about,...learning

Reply With Quote
  #8  
Old January 13th, 2003, 04:02 PM
Spathe Spathe is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 7 Spathe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Correction

PHP Code:
die('Error: Header redirection failed.');

// and not

exit('Error: Header redirection failed.'); 



Reply With Quote
  #9  
Old January 14th, 2003, 02:24 AM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
Re: Correction

Quote:
Originally posted by Spathe
PHP Code:
die('Error: Header redirection failed.');

// and not

exit('Error: Header redirection failed.'); 




Why? die() is just an alias of exit() so both will work

Reply With Quote
  #10  
Old January 14th, 2003, 02:40 PM
Spathe Spathe is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 7 Spathe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Oh yes, you are right

I have the "bad" habit to take die() when I want to output the status and exit when I output nothing... it's for this reason i maked this mistake

Conclusion : I will RTFM before posting philosophical replies

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Does PHP support a Redirect function?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway