 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
01-19-2008, 09:49 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Posts: 27
Thanks: 1
|
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
|
|
|
|
01-19-2008, 09:51 PM
|
#2 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
|
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.
|
|
|
01-19-2008, 09:54 PM
|
#3 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Posts: 27
Thanks: 1
|
This file is included in another file.
|
|
|
|
01-19-2008, 09:56 PM
|
#4 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
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.
|
|
|
|
01-19-2008, 09:55 PM
|
#5 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Posts: 27
Thanks: 1
|
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?
|
|
|
|
01-19-2008, 10:00 PM
|
#6 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Posts: 27
Thanks: 1
|
What would this function look like in Javascript? With all the output. I'm not the best one to JavaScript
|
|
|
|
01-19-2008, 10:07 PM
|
#7 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
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
|
|
|
|
01-19-2008, 10:12 PM
|
#8 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Posts: 27
Thanks: 1
|
Well it doesnt quite work. How should I get the URL in?
|
|
|
|
01-19-2008, 10:32 PM
|
#9 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
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
|
|
|
|
01-19-2008, 11:09 PM
|
#10 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
Quote:
Originally Posted by Village Idiot
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.
|
|
|
|
01-19-2008, 11:12 PM
|
#11 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Quote:
Originally Posted by xenon
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.
|
|
|
|
01-20-2008, 06:44 PM
|
#12 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 264
Thanks: 2
|
Quote:
Originally Posted by xenon
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
|
|
|
|
01-19-2008, 11:04 PM
|
#13 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
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
|
|
|
01-19-2008, 11:22 PM
|
#14 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
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
|
|
|
|
01-19-2008, 11:40 PM
|
#15 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
You shouldnt stop execution because they disabled javascript, the site has to work fully for them.
|
|
|
|
01-20-2008, 03:43 PM
|
#16 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
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.
|
|
|
|
01-20-2008, 04:20 PM
|
#17 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
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. 
|
|
|
|
01-20-2008, 06:54 PM
|
#18 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Quote:
Originally Posted by Salathe
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. 
|
|
|
|
01-20-2008, 06:53 PM
|
#19 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
|
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.
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|