PDA

View Full Version : Logout link (php) not copying from template to webpages


whitedragon101
08-18-2009, 04:59 PM
I have put a logout php link in my template for a website and used the inbuilt function to write the logout code for me. This works fine when I preview the site locally. However when I loaded the site onto the web I got the following error:


Warning: Cannot modify header information - headers already sent by
(output started at /home/jsite/public_html/webpages/company_area/job_requests.php:138)
in /home/jsite/public_html/webpages/company_area/job_requests.php on line 179Now this was basically the same error I got when loading any page on the web and a quick google said it was the presence of spaces outside the <?php ?> tag. So I removed the spaces I saw and the error stopped occuring. But when I press the logout link the above error appears again. I have used the following template:

<!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=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>customer area template</title>
<!-- TemplateEndEditable -->
<link href="../css/customer_area_style1.css" rel="stylesheet" type="text/css" />
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);

$logoutGoTo = "../webpages/company_area/company_login.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?></head>

<body>
<div id="wrapper">
<div id="banner"><img src="../images/my banner1.jpg" width="800" height="158" alt="banner" /></div>
<div id="top_bar"><!-- TemplateBeginEditable name="Subtitle" -->Subtitle<!-- TemplateEndEditable --></div>
<div id="body_wrapper">
<div id="left_bar">
<p>&nbsp; </p>
<p>&nbsp;</p>
<p><a href="../webpages/company_area/job_requests.php">Job Requests</a></p>
<p>&nbsp;</p>
<p><a href="../webpages/company_area/sent_requests.php">Sent Requests</a></p>
<p>&nbsp;</p>
<p><a href="../webpages/company_area/request_responses.php">Request Responses</a></p>
<p>&nbsp;</p>
<p><a href="../webpages/company_area/worker_payments.php">Worker Payments</a></p>
<p>&nbsp;</p>
<p><a href="../webpages/company_area/customer_details.php">Customer Details</a></p>
<p>&nbsp;</p>
<p>Agency Details</p>
<p>&nbsp;</p>
<p><a href="<?php echo $logoutAction ?>">Logout</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
<div id="main_content"><!-- TemplateBeginEditable name="main_content" -->
<p>main_contentmain_contentmain_contentmain_contentma in_contentmain_contentmain_contentmain_content</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<!-- TemplateEndEditable --></div>
</div>
<div id="footer">Content for id "footer" Goes Here</div>
</div>
</body>
</html>

Any idea how to get rid of the error from using this template for logging out?

whitedragon101
08-18-2009, 06:08 PM
Whoops just realised the thread title is a little misleading. To explain:

I managed to solve the error by putting the logout code as the very first thing in the template. If i then create a new page based on this template the code is copied over (appearing at the very top of the webpage) and no error is received when logging out. However existing pages using the template do not receive the logout code.

DWcourse
08-18-2009, 09:25 PM
In pages created from templates there's a line that looks like:

<!-- InstanceBegin template="/Templates/default.dwt" codeOutsideHTMLIsLocked="false" -->

I think you want that to be set to true but offhand I'm not sure where the setting is.

DWcourse
08-18-2009, 09:39 PM
I believe you need to add this line to the top of your template file

<!-- TemplateInfo codeOutsideHTMLIsLocked="true" -->

(I'm not absolutely certain about this so I'd back up before you start messing around)