TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-19-2008, 09:49 PM   #1 (permalink)
The Contributor
Newcomer 
 
Join Date: Jan 2008
Posts: 27
Thanks: 1
lesP is on a distinguished road
Default header(location) does not work?

This doesnt work:
PHP Code:
<?

header
('Location: index.php?mode=statistikker&mode2=statistikker&action='.$_POST[statistikpost].'&spil='.$_GET[id].'&overordnet='.$_GET[overordnet].'');

?>
I get this error:

Warning: Cannot modify header information - headers already sent by (output started
lesP is offline  
Reply With Quote
Old 01-19-2008, 09:51 PM   #2 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default

With header(), you can't have any output or whitespace outputted to the browser before that function is called. If that's the entire code for the page, try getting rid of the blank lines. If it still doesn't work, put the <? and ?> on the same line as the function.
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
Old 01-19-2008, 09:54 PM   #3 (permalink)
The Contributor
Newcomer 
 
Join Date: Jan 2008
Posts: 27
Thanks: 1
lesP is on a distinguished road
Default

This file is included in another file.
lesP is offline  
Reply With Quote
Old 01-19-2008, 09:55 PM   #4 (permalink)
The Contributor
Newcomer 
 
Join Date: Jan 2008
Posts: 27
Thanks: 1
lesP is on a distinguished road
Default

Then what should I do? I want the script to do like this line.

EDIT: Maybe I could use some JavaScript to send the user to the page?
lesP is offline  
Reply With Quote
Old 01-19-2008, 09:56 PM   #5 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Then you must send that header before any actual output. If you can't do that, use another redirection method (like a meta tag - which will invalidate your html - or a javascript code).
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-19-2008, 10:00 PM   #6 (permalink)
The Contributor
Newcomer 
 
Join Date: Jan 2008
Posts: 27
Thanks: 1
lesP is on a distinguished road
Default

What would this function look like in Javascript? With all the output. I'm not the best one to JavaScript
lesP is offline  
Reply With Quote
Old 01-19-2008, 10:07 PM   #7 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Just do this:

PHP Code:
$url 'http://www.mysite.com';

echo 
"<script language=\"javascript\">
location.href=\"
$url\";
</script>"
;
exit; 
// Stops executing page, just stops if JS is disabled 
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 01-19-2008, 10:12 PM   #8 (permalink)
The Contributor
Newcomer 
 
Join Date: Jan 2008
Posts: 27
Thanks: 1
lesP is on a distinguished road
Default

Well it doesnt quite work. How should I get the URL in?
lesP is offline  
Reply With Quote
Old 01-19-2008, 10:32 PM   #9 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Dont use javascript, too many people have it disabled. Use this code

Code:
 <META HTTP-EQUIV="Refresh"
      CONTENT="5; URL=html-redirect.html">
5 being the number of seconds before refresh (put 0 for instant) and URL being the url to go to
__________________

Village Idiot is offline  
Reply With Quote
Old 01-19-2008, 11:04 PM   #10 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

What is being output / sent to the browser before the redirect header? If you are doing an instant redirect do you really need to output something first since I'm guessing no-one would see it?

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-19-2008, 11:09 PM   #11 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
Dont use javascript, too many people have it disabled.
lol...so how's in the '80s? Is it true that they run naked on the streets? No, really now, who turns off Javascript nowadays (and what would be the purpose)?

Javascript redirection method:

Code:
function do_redirect( url )
{
    window.location = url;
}
..then, in your php code, you could do something like so:

PHP Code:
echo '<script type="text/javascript">do_redirect("http://someurl.com/apage.html");</script>'
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-19-2008, 11:12 PM   #12 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
lol...so how's in the '80s? Is it true that they run naked on the streets? No, really now, who turns off Javascript nowadays (and what would be the purpose)?
A small percentage, but it still amounts a a lot of people. It is something you still need to cater to. They do it because security holes have came up, some of them recently. I see it as paranoia, but I'm not the client.
__________________

Village Idiot is offline  
Reply With Quote
Old 01-19-2008, 11:22 PM   #13 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Hello, that's why I included the exit; command so if for some odd reason JS is disabled then it just exits, stops. xenon's method works but so does mine. As for the putting in the URL...

PHP Code:
$url 'http://www.mysite.com'// *Cough*

echo "<script language=\"javascript\">
location.href=\"
$url\";
</script>"
;
exit; 
// Stops executing page, just stops if JS is disabled 
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 01-19-2008, 11:40 PM   #14 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

You shouldnt stop execution because they disabled javascript, the site has to work fully for them.
__________________

Village Idiot is offline  
Reply With Quote
Old 01-20-2008, 03:43 PM   #15 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

OK, then put in an echo with a link before the exit; command. Just keep in mind that the META method can be disabled too.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 01-20-2008, 04:20 PM   #16 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Rather than working around the problem (ie, finding a new way to redirect) why not solve the initial problem and be done with it? Sending out headers should never, ever, come after any content has been sent out. Re-structure your PHP code so that the redirect can happen before anything is outputted and bam, no need to bother with resorting to HTML/JavaScript/ask-them-politely redirects.

Also -- a minor point in the grand scheme of things -- is that the value in the Location header should be a full URL: http://domain.com and all the rest. It will work with just index.php... but just because something works, doesn't make it right.
Salathe is offline  
Reply With Quote
Old 01-20-2008, 06:44 PM   #17 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
lol...so how's in the '80s? Is it true that they run naked on the streets? No, really now, who turns off Javascript nowadays (and what would be the purpose)?

Javascript redirection method:

Code:
function do_redirect( url )
{
    window.location = url;
}
..then, in your php code, you could do something like so:

PHP Code:
echo '<script type="text/javascript">do_redirect("http://someurl.com/apage.html");</script>'
I go around with javascript disabled o.O
TlcAndres is offline  
Reply With Quote
Old 01-20-2008, 06:53 PM   #18 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default

I sometimes go without JavaScript because I disable it to test sites that use it (to see if they work without it), and forget I turned it off.
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
Old 01-20-2008, 06:54 PM   #19 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
Rather than working around the problem (ie, finding a new way to redirect) why not solve the initial problem and be done with it? Sending out headers should never, ever, come after any content has been sent out. Re-structure your PHP code so that the redirect can happen before anything is outputted and bam, no need to bother with resorting to HTML/JavaScript/ask-them-politely redirects.
I agree with everything you said here.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:58 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design