Header() problem

Links for php scripts

Moderators: macek, egami, gesf

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

Header() problem

Post by 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

Post by 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

Post by 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'];

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

Re: Header() problem

Post by 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>

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests