Jump to content

Headers already sent


truenitin

headers already sent  

1 member has voted

  1. 1. headers already sent

    • 1
      1
    • 2
      0


Recommended Posts

Notice: Undefined variable: p in c:\program files\easyphp1-8\www\index.php on line 11

Notice: Undefined variable: p in c:\program files\easyphp1-8\www\index.php on line 19

Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\index.php:11) in c:\program files\easyphp1-8\www\index.php on line 23

I am getting this error when i run the following code.

<?php

if (isset($_GET['page']) and $_GET['page'] != "") {
$p = $_GET['page'];
}
if (strpos($p,"..")) {
    die("Bad page request");
}

if (!$p) $p = "main";
$content_file=$_SERVER["DOCUMENT_ROOT"]."/".$p.".php";
if (!file_exists($content_file)) {
    header("Location: {$_SERVER["PHP_SELF"]}");
    exit();
}

$title = ($p) ? "$p - My Site!" : "Main page - My Site!";
include("header.php");
include($content_file);
include("footer.php");
?>

i get this error when i use session_register also.

A possible solution?

Nitin
Link to comment
https://forums.phpfreaks.com/topic/13642-headers-already-sent/
Share on other sites

Try this instead:
[code=php:0]if (isset($_GET['page']) and $_GET['page'] != "")
{
    $p = $_GET['page'];
}
else
{
    $p = "main";
}

if (strpos($p, ".."))
{
        die("Bad page request");
}

$content_file = $_SERVER["DOCUMENT_ROOT"] . "/" . $p . ".php";

if (!file_exists($content_file))
{
    header("Location: {$_SERVER['PHP_SELF']}");
    exit();
}

$title = ($p) ? "$p - My Site!" : "Main page - My Site!";

include("header.php");
include($content_file);
include("footer.php");[/code]
Link to comment
https://forums.phpfreaks.com/topic/13642-headers-already-sent/#findComment-52901
Share on other sites

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.