Jump to content

Archived

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

adamjnz

Please help with problem

Recommended Posts

I am having a 'Cannot modify header information - headers already sent' problem. I have read the other posts about the cause being trying to send header information AFTER the HTML starts.


I have checked my code and the line it is erroring on is BEFORE the HTML starts. Any idea what would cause this?

[code]<?php require_once('../Connections/ppl_frontend.php'); ?>
<?php require_once('../Connections/ppl_frontend.php'); ?>
<?php
//initialize the 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_unregister('MM_Username');
  session_unregister('MM_UserGroup');
    
  $logoutGoTo = "./";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
session_start();
$MM_authorizedUsers = "Administrator";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
  // For security, start by assuming the visitor is NOT authorized.
  $isValid = False;

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
  // Therefore, we know that a user is NOT logged in if that Session variable is blank.
  if (!empty($UserName)) {
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
    // Parse the strings into arrays.
    $arrUsers = Explode(",", $strUsers);
    $arrGroups = Explode(",", $strGroups);
    if (in_array($UserName, $arrUsers)) {
      $isValid = true;
    }
    // Or, you may restrict access to only certain users based on their username.
    if (in_array($UserGroup, $arrGroups)) {
      $isValid = true;
    }
    if (($strUsers == "") && false) {
      $isValid = true;
    }
  }
  return $isValid;
}

$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {  
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo);
  exit;
}
?>
<?php
mysql_select_db($database_ppl_frontend, $ppl_frontend);
$query_admin = "SELECT * FROM ppl_admin";
$admin = mysql_query($query_admin, $ppl_frontend) or die(mysql_error());
$row_admin = mysql_fetch_assoc($admin);
$totalRows_admin = mysql_num_rows($admin);

mysql_select_db($database_ppl_frontend, $ppl_frontend);
$query_products = "SELECT * FROM ppl_products";
$products = mysql_query($query_products, $ppl_frontend) or die(mysql_error());
$row_products = mysql_fetch_assoc($products);
$totalRows_products = mysql_num_rows($products);

mysql_select_db($database_ppl_frontend, $ppl_frontend);
$query_orders = "SELECT * FROM ppl_orders ORDER BY orderID DESC";
$orders = mysql_query($query_orders, $ppl_frontend) or die(mysql_error());
$row_orders = mysql_fetch_assoc($orders);
$totalRows_orders = mysql_num_rows($orders);
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
?>
<?php do { ?>
<?php

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "add_user")) {
  $insertSQL = sprintf("INSERT INTO ppl_user_products (username, productID, product_price, product_quantity) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($row_products['productID'], "int"),
                       GetSQLValueString($row_products['default_price'], "int"),
                       GetSQLValueString($row_products['default_quantity'], "int"));

  mysql_select_db($database_ppl_frontend, $ppl_frontend);
  $Result1 = mysql_query($insertSQL, $ppl_frontend) or die(mysql_error());
} ?>
<?php } while ($row_products = mysql_fetch_assoc($products)); ?>
<?php
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "add_user")) {
  $insertSQL = sprintf("INSERT INTO ppl_users (username, password, access, email, real_name, company, post_add1, post_add2, post_add_sub, post_add_city, ship_add1, ship_add2, ship_add_sub, ship_add_city) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['access'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['real_name'], "text"),
                       GetSQLValueString($_POST['company'], "text"),
                       GetSQLValueString($_POST['post_add1'], "text"),
                       GetSQLValueString($_POST['post_add2'], "text"),
                       GetSQLValueString($_POST['post_add_sub'], "text"),
                       GetSQLValueString($_POST['post_add_city'], "text"),
                       GetSQLValueString($_POST['ship_add1'], "text"),
                       GetSQLValueString($_POST['ship_add2'], "text"),
                       GetSQLValueString($_POST['ship_add_sub'], "text"),
                       GetSQLValueString($_POST['ship_add_city'], "text"));

  mysql_select_db($database_ppl_frontend, $ppl_frontend);
  $Result1 = mysql_query($insertSQL, $ppl_frontend) or die(mysql_error());

  $insertGoTo = "users.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!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>etc etc etc[/code]

Share this post


Link to post
Share on other sites
If your code is spitting out another error that counts as html too. Also, why are you initializing the session twice?

Share this post


Link to post
Share on other sites
[!--quoteo(post=365453:date=Apr 17 2006, 04:41 PM:name=ypirc)--][div class=\'quotetop\']QUOTE(ypirc @ Apr 17 2006, 04:41 PM) [snapback]365453[/snapback][/div][div class=\'quotemain\'][!--quotec--]
If your code is spitting out another error that counts as html too.[/quote]
I don't know what this means

[!--quoteo(post=365453:date=Apr 17 2006, 04:41 PM:name=ypirc)--][div class=\'quotetop\']QUOTE(ypirc @ Apr 17 2006, 04:41 PM) [snapback]365453[/snapback][/div][div class=\'quotemain\'][!--quotec--]Also, why are you initializing the session twice?[/quote]

Didn't know I was

Share this post


Link to post
Share on other sites
It means if your code has an error and complains about it to the browser, it is sending headers. Also, if you look at your code you have session_start() twice...remove the second one and that will probably solve your problem.

Share this post


Link to post
Share on other sites
[!--quoteo(post=365456:date=Apr 17 2006, 05:00 PM:name=ypirc)--][div class=\'quotetop\']QUOTE(ypirc @ Apr 17 2006, 05:00 PM) [snapback]365456[/snapback][/div][div class=\'quotemain\'][!--quotec--]
It means if your code has an error and complains about it to the browser, it is sending headers. Also, if you look at your code you have session_start() twice...remove the second one and that will probably solve your problem.
[/quote]

Still get same error

Share this post


Link to post
Share on other sites
Solved now. I copied and pasted my code out of the PHP file and pasted it back in bit by bit to try and find the errors. But once it was all pasted back in it worked fine.

Share this post


Link to post
Share on other sites

×

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.