Jump to content

PHP Block inside a PHP Block?


Lamez

Recommended Posts

ok I am the noobie that is asking a lot of questions, but the best way for me to learn is to get hands on.

 

Anyways here is my problem

 

I want to include my logout session in my members page so it would be members.php?process=logout

 

the problem is, its not logging the user out.

 

I get this error

 

Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home48c/sub007/sc33591-LWQU/www/login/_members/members.php:6) in /mounted-storage/home48c/sub007/sc33591-LWQU/www/login/_members/members.php on line 44

 

Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home48c/sub007/sc33591-LWQU/www/login/_members/members.php:6) in /mounted-storage/home48c/sub007/sc33591-LWQU/www/login/_members/members.php on line 45

 

 

here is line 44 and 45

 

setcookie("loggedin", "TRUE", time()-(3600 * 24)); //logs the uer out
setcookie("$username");

 

here is whole code

 

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="../../style/default.css"/>
<?php include ("../../style/include/title.php"); ?>
</head>

<body>


 <div class="logo"><?php
include ("../../style/include/header.php");
?></div>

       <div class="spacer"></div>

<?php
include ("menu/menu.php");
?>

<div class="box"><font size="3">
  <center>
<?php
$username = $_COOKIE['loggedin'];
if (!isset($_COOKIE['loggedin'])) die("You are not logged in, <a href=../../login.php>click here</a> to login."); //add meta redirect here
echo "<u>Welcome</> <b>$username</b>";
?>
</center></font></div>


<?php
$getlink = $_GET["process"];

if ($getlink == "members_list") {
print <<<MBL
<div class="box">
<p><center><font size="3">Coming Soon</font></center></p>
</div>
MBL;
}
elseif ($getlink == "logout") {

setcookie("loggedin", "TRUE", time()-(3600 * 24)); //logs the uer out
setcookie("$username");

print <<<LOG
<meta http-equiv="Refresh" content="5; URL=../../index.php">
      <div class="box">
<center><font size="3">You are logged out.</font></center>
</div>
LOG;
}
else { //The Main Links
print <<<NEW
     </u>

 <div class="boxn">
  <font size="3">
     </u>

       <div class="left">
   <br />
   <br />
          <p><a href="upload/udsection.php">Upload\Download Section</a>
          <br />
          <br />
          <a href="proxy/goto.php">Lamez's Proxy</a> 
	   <br />
	  <br /> 
          <a href="arcade/playgame.php">Arcade</a><font color="#FF0000" size="1"><font color="#000000">*</font>Coming Soon!</font></p>
	  </div>


         <div class="right">
	 <br />
	 <br />
          <p><a href="contact.php">Suggestions\Contact Lamez</a>		  
	  <br />
          <br />
          <a href="news/news.php">Website News</a>
	  <br />
          <br />
          <font color="#FF0000" size="1">Coming Soon!<font color="#000000">*</font></font><a href="lamez/corner.php">Lamez's Corner</a></p>
           </div>
     </div>
NEW;
}	 
?>
<?php
include ("../../style/include/footer.php");
?>		
</body>
</html>

 

what am I doing wrong? I Please Help! Thanks Guys!

Link to comment
https://forums.phpfreaks.com/topic/66710-php-block-inside-a-php-block/
Share on other sites

Set_cookie

 

setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers' date=' cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace.[/quote']

 

so the same rule as a session, see the pinned post about headers

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.