header error in php session

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default header error in php session

    I am trying to create site where my members login and get post listings of
    products to my database. I have no problem setting up the site to authenticate
    users and let them browse from page to page. The problem lies within the second
    form. When they are filling out the form for their listing (they are already
    logged in) and they hit submti, the same page is reloaded with an error that
    says: "Warning: Cannot modify header information - headers already sent by
    (output started at
    /home/finallyt/public_html/websites/bigredhat/scripts/create_listing.php:9) in
    /home/finallyt/public_html/websites/bigredhat/scripts/create_listing.php on
    line 105" I have the session start at the top of all the restricted pages, just
    below: <?php require_once('../Connections/red_listing.php'); ?> If i put the
    session start statement above this line, my recordsets do not work correctly.
    Someone please help! If you need more information, or anything you can email me
    at [email]bseefeld@finallythebasics.com[/email] Thanks!

    barbedwire103 Guest

  2. Similar Questions and Discussions

    1. #14636 [Com]: Session variables are lost when redirecting to a url using header() function.
      ID: 14636 Comment by: andrew dot whale at which dot net Reported By: kannan at tmsassociates dot com Status: ...
    2. header() redirection/session variable problem
      Hello, I'm having an odd problem with combining an authentication session variable with header() redirection. Basically I have an authentication...
    3. Session cookie in HTTP header
      I'm writing an application to authenticate a user using a challenge response mechanism. The client and server components of the application talk...
    4. [PHP] session header issue
      <snip> The Location: header requires a correctly formed URL, ie http://... </snip> I'm running fine using only Location:home.php on Mozilla & IE...
    5. session header issue
      I've got a site with a login authentication script in a file called login.php. Every page has a simple session check on top of it, as well as line...
  3. #2

    Default Re: header error in php session

    Here is the code for the page. Its just the php that is above the <html> tag.
    That is where the problem seems to lie.
    <?php
    // FELIXONE - 2002 SB by Felice Di Stefano - [url]www.felixone.it[/url]
    session_start();
    ?>
    <?php require_once('../Connections/red_conn.php'); ?>
    <?php require_once('../Connections/red_listing.php'); ?>


    <?php
    session_start();
    $MM_authorizedUsers = "";
    $MM_donotCheckaccess = "true";

    // *** 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 == "") && true) {
    $isValid = true;
    }
    }
    return $isValid;
    }

    $MM_restrictGoTo = "access_denied.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
    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']);
    }

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "listing")) {
    $insertSQL = sprintf("INSERT INTO create_listing (username, title, type,
    levels, `size`, description, comments, address, city, country, utiltities)
    VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
    GetSQLValueString($_POST['username'], "text"),
    GetSQLValueString($_POST['title'], "text"),
    GetSQLValueString($_POST['type'], "text"),
    GetSQLValueString($_POST['levels'], "text"),
    GetSQLValueString($_POST['size'], "text"),
    GetSQLValueString($_POST['description'], "text"),
    GetSQLValueString($_POST['comments'], "text"),
    GetSQLValueString($_POST['address'], "text"),
    GetSQLValueString($_POST['location'], "text"),
    GetSQLValueString($_POST['country'], "text"),
    GetSQLValueString(isset($_POST['cable']) ? "true" : "",
    "defined","'Y'","'N'"));

    mysql_select_db($database_red_listing, $red_listing);
    $Result1 = mysql_query($insertSQL, $red_listing) or die(mysql_error());

    $insertGoTo = "../index.htm";
    if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s", $insertGoTo));
    }

    $colname_Recordset1 = "-1";
    if (isset($_SESSION['username'])) {
    $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_SESSION['username'] :
    addslashes($_SESSION['username']);
    }
    mysql_select_db($database_red_conn, $red_conn);
    $query_Recordset1 = sprintf("SELECT * FROM login WHERE username = '%s'",
    $colname_Recordset1);
    $Recordset1 = mysql_query($query_Recordset1, $red_conn) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    ?>

    barbedwire103 Guest

  4. #3

    Default Re: header error in php session

    barbedwire103 wrote:
    > "Warning: Cannot modify header information - headers already sent by
    This warning means that some output has been sent to the browser before
    the call to session_start() or before any call to header() in your PHP
    script. Looking at the code in your second post, there are three obvious
    problems:

    1. You have two calls to session_start(). There should be only one on a
    page.

    2. You have calls to external scripts (your two connections). You need
    to check both pages in Dreamweaver code view to make sure that there is
    no whitespace before the opening PHP tag or after the closing one. Turn
    on line numbering. If there are any line numbers below your closing tag,
    put your cursor as low down on the page as it will go, and start
    deleting with the backspace key until the cursor is right next to the ?>
    tag.

    3. You have whitespace here:

    <?php require_once('../Connections/red_listing.php'); ?>


    <?php
    session_start();

    Those extra lines between the PHP tags send output to the browser, and
    prevent the session starting.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    [url]http://computerbookshelf.com[/url]
    David Powers Guest

  5. #4

    Angry Re: header error in php session

    Im coding a login system, which i have already coded on my school server and communicated with its database, and everything worked perfect, now i use the same code and use a go-daddy linux box and am connected to the database and everything, but when i try to login as below i get these 5 errors. SOMEBODY please help lol Have already read multiple forums and tried many different solutions, white spaces, and others. But doesn't make sense to me why it would work on my school server with no problems and not this one.

    ERRORS:
    1-Warning: Cannot modify header information - headers already sent by (output started at /home/content/50/8151650/html/TSP/Html/trial.php:6) in /home/content/50/8151650/html/TSP/Html/trial.php on line 66

    2-Warning: Cannot modify header information - headers already sent by (output started at /home/content/50/8151650/html/TSP/Html/trial.php:6) in /home/content/50/8151650/html/TSP/Html/trial.php on line 67

    3-Warning: session_register() [function.session-register]: Cannot send session cookie - headers already sent by (output started at /home/content/50/8151650/html/TSP/Html/trial.php:6) in /home/content/50/8151650/html/TSP/Html/trial.php on line 69

    4-Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/content/50/8151650/html/TSP/Html/trial.php:6) in /home/content/50/8151650/html/TSP/Html/trial.php on line 69

    5-Warning: Cannot modify header information - headers already sent by (output started at /home/content/50/8151650/html/TSP/Html/trial.php:6) in /home/content/50/8151650/html/TSP/Html/trial.php on line 73
    CODE:
    // If Login attempted
    if(isset($_POST['Submit'])){
    // Connect to server and select databse.
    mysql_connect($hostname, $username, $password)or die("Cannot Connect");
    mysql_select_db($dbname)or die("cannot select DB");
    // username and password sent from form
    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword'];
    $user = $myusername;
    $pass = $mypassword;
    // To protect MySQL injection (more detail about MySQL injection)
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    $sql="SELECT * FROM $tbl_name WHERE user='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);
    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row
    if($count==1){
    if(isset($_COOKIE['user'])){
    setcookie('user',$user, time()-3600);
    setcookie('password',$pass, time()-3600);
    }
    if(isset($_COOKIE['adminuser'])){
    setcookie('adminuser',$user, time()-3600);
    setcookie('adminpassword',$pass, time()-3600);
    }
    setcookie('user',$user);
    setcookie('password',$pass);
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    session_register("myusername");
    session_register("mypassword");
    ?>
    <input type="hidden" name="user" value="<? print $myusername ?>"/>
    <? header("location:loggedin2.php");
    }
    }
    ?>
    <div id="TOP">
    <font color="#000000">
    <form name="form1" method="post" action="trial.php">
    <font color="#FFFFFF">
    <table>
    <Tr><Td rowspan="2"><h1>Kyle Hockenberry's Site</h1></Td>
    <td style="padding-left:500px;" valign="bottom">UserName</td>
    <td valign="bottom">Password</td>
    </Tr><tr>
    <td style="padding-left:500px;"><input name="myusername" type="text" id="myusername"></td>
    <td><input name="mypassword" type="password" id="mypassword"></td>
    <td><input type="submit" name="Submit" value="Login" /></td><td><? if(isset($_POST['Submit'])){
    echo ('<font color="#FFFFFF" size="-1"><i>* Wrong Username or Password</i></font>');
    }
    ?></Td></tr>
    </table>
    </font>
    </form>
    </font>
    </div>
    </body>
    </html>
    Kyle Hockenberry Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139