Header() problem

Links for php scripts

Moderators: macek, egami, gesf

andor1995
New php-forum User
New php-forum User
Posts: 15
Joined: Mon Jan 09, 2012 11:39 pm

Header() problem

Postby andor1995 » Mon Feb 20, 2012 7:23 am

Hey, I'm working on a website and on my pc it works fine, but on my host it keeps giving me errors.

Error:

Code: Select all

Warning: Cannot modify header information - headers already sent by /code]

Code:
[code]if(isset($_COOKIE['username'])):
else:
header ("location:login.php");
endif;
$user = $_COOKIE['username'];

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Header() problem

Postby egami » Mon Feb 20, 2012 7:24 am

header("Location: page.php");

case.. case is important.

andor1995
New php-forum User
New php-forum User
Posts: 15
Joined: Mon Jan 09, 2012 11:39 pm

Re: Header() problem

Postby andor1995 » Mon Feb 20, 2012 7:28 am

Changed it, but it's still not working.

new code:

Code: Select all

if(isset($_COOKIE['username'])):
else:
header ("Location:login.php");
endif;
$user = $_COOKIE['username'];

Christopher
New php-forum User
New php-forum User
Posts: 3
Joined: Mon Feb 20, 2012 7:31 am

Re: Header() problem

Postby Christopher » Mon Feb 20, 2012 7:34 am

are you sure this the only snippet of code all the code is needed to verify the source of the problem.

andor1995
New php-forum User
New php-forum User
Posts: 15
Joined: Mon Jan 09, 2012 11:39 pm

Re: Header() problem

Postby andor1995 » Mon Feb 20, 2012 7:38 am

Full code

Code: Select all

<?
if(isset($_COOKIE['username'])):
else:
header ("Location:login.php");
endif;
$user = $_COOKIE['username'];
?>
<div id="header">
<a href="index.php"><img src="../../images/acp/logo.png" width="400" height="60" longdesc="http://andor-cms.no-ip.info/admin/" /></a>
<?
echo '<div id="user>"<a>' . $user . ' ' . '<a href="logout.php">Logout</a></a></div>';
?>
</div>


Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest

cron