Header not working *MOVED*

scorch94

Member
Messages
228
Reaction score
0
Points
16
<?php
if (!isset($_COOKIE['user']))
{
header('Location: login.php');
die;
}
?>

When I tested it on my PC (running WampServer 5), it worked out.
But now hosted on Stoli, it says:

Warning: Cannot modify header information - headers already sent by (output started at /home/scorch94/public_html/gsm/index.php:2) in /home/scorch94/public_html/gsm/index.php on line 5

Any help?
Edit:
Sorry for bumping, but I really need an answer :)
 
Last edited:

Russ

<b>Retired *****</b>
Messages
3,168
Reaction score
2
Points
38
Re: Header not working

from what i'm reading on it, that must be at the top of the file, even before <html>, it has to process before ANY html is sent to the browser, otherwise that error will occur. Then, someone else said:

Here's how header() works

You can put header("Location: whateverpage.php"); anywhere you want. Top/bottom of script doesnt matter. What is important is to put exit(); right after. The reason being that all your doing with the header call is changing the headers, the script wants to finnish before it uses those new headers. So if you stop the script then you will redirect the page.

Also, if you tried echoing or printing anything to the screen before header(), then it wont work because you're basiclly trying to say you want a page returned to the user yet you also want to go to another page. When you echo, you are saying that the current heading is what you want. So thats why when you change the heading later it says "Cant change header"
 

scorch94

Member
Messages
228
Reaction score
0
Points
16
Re: Header not working

Sorry 'bout this guys, but I really need help :(
x10 is my favorite host, I put all the trust in you, guys! You're the best!
But nobody helps. I understand - you guys are busy. So I'm bumping this.

Sorry :(
 
Last edited:

Russ

<b>Retired *****</b>
Messages
3,168
Reaction score
2
Points
38
Re: Header not working

I am going to move this to another forum, this really isn't the correct one, Maybe someone there will help ya.
 

Hazirak

New Member
Messages
197
Reaction score
0
Points
0
If you're editing header information, that particular block of PHP MUST start on the first line of the file. For example, something like...
HTML:
<?php
if (!isset($_COOKIE['user']))
{
	header('Location: login.php');
	die;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
... etc
... would work.
 
Last edited:

scorch94

Member
Messages
228
Reaction score
0
Points
16
Now I realized that cPanel for some reason put some weird characters before the <?php tag. I removed them, and it all works now :)

Sorry for posting this useless thread :(
 
Last edited:

npicstore82

New Member
Messages
4
Reaction score
0
Points
0
Re: Header not working *MOVED* same problems with all header

Warning: Cannot modify header information - headers already sent by (output started at /home/picstore/public_html/delete_album.php:1) in /home/picstore/public_html/delete_album.php on line 16

<?php
include 'init.php';

if(!logged_in()){
header('Location: index.php');
exit();
}
if(album_check($_GET['album_id']) === false){
header('Location: albums.php');
exit();
}

if(isset($_GET['album_id'])){
$album_id = $_GET['album_id'];
delete_album($album_id);
header('Location: albums.php');
exit();
}


?>

Please help...
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Make sure nothing -- absolutely nothing -- happens before the <?php tag. The "usual suspect" is a Byte Order Mark (BOM) in a file stored as unicode (utf-8). Your text editor/IDE should allow you to drop the BOM.
 

npicstore82

New Member
Messages
4
Reaction score
0
Points
0
ok thanks got it

---------- Post added at 07:51 AM ---------- Previous post was at 07:48 AM ----------

ok thanks got it


one more problem


move_uploaded_file() not working


please help...
 

Dead-i

x10Hosting Support Ninja
Community Support
Messages
6,084
Reaction score
368
Points
83
ok thanks got it


one more problem


move_uploaded_file() not working


please help...
Please keep all discussion about that in the topic you created.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
@npicstore82: Don't threadjack. Don't revive long dead threads (this one is 3 3/4 years old). It's bad netiquette.
 
Top