SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help me with this wwarning "Warning:session_start()"

    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home3/nyhungry/public_html/includes/header.php:7) in /home3/nyhungry/public_html/includes/header.php on line 57

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home3/nyhungry/public_html/includes/header.php:7) in /home3/nyhungry/public_html/includes/header.php on line 57
    ( Hungers)

    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=utf-8" />
    <link type="text/css" href="stylesheets/webpageprueba.css" rel="stylesheet" media="all" />
    <title>www.Nyhungry.com</title>
    <script type="text/javascript" src="scripts/prototype.js"></script>
    <script type="text/javascript" src="scripts/rating.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    <script type="text/javascript">
    (
    function()
    {
      var default_image = $('td.largethumb img').attr('src');
      $('table.smallthumbs a').mouseover(function() { $('td.largethumb img').attr('src', $('img', this).attr('src')); });
    });
    </script>
    </head>
    
    
    <body>
    
    
    
    <div id="sidebar1">
    <ul id="mainNav">
          <li id="home"><a href="restaurants/index.php" title="All restaurants inside nyhungry" class="first">Home</a></li>
                    <li id="music"><a href="../../Take Outs/Take Outs frontpage.html" title="Information about all take Outs">Hungry for Music!</a></li>
                  <li id="pizzerias"><a href="../../Pizzeria/Pizzeria frontpage.html" title="All the pizzerias inside nyhungry">Contact us</a></li>
                       </ul>
    <!-- end #sidebar1 --></div>
    <!--<table id="restaurantview">
    
    <a href=""><td width="40" id="contenido1">tropiezo></td></a>
    <a href=""><td width="40" id="contenido2">colozar1></td></a>
    <a href=""><td width="40" id="contenido3">colozar2></td></a>
    <a href=""><td width="40" id="contenido4">colozar3></td></a> 
    <a href=""><td width="40" id="contenido4">colozar4></td></a>
    <a href=""><td width="40" id="contenido4">colozar3</td></a>
    </table>-->
    
    <div id="right">
    
    <?php /*?><?php
     $data=file_get_contents('counter.dat');
     $counter=unserialize($data);
     $counter[$_SERVER["REMOTE_ADDR"]]=time();
     foreach ($counter as $key => $value) if ($value < (time()-180)) unset $counter($k);
     $data=serialize($counter);
     file_put_contents('counter.dat', $data);
     echo'<p>count($counter)." viewing"</p>';
    ?> </div><?php */?>
    
    <?php  
     session_start(); // this is Line 57 where the warning is coming from... 
    
    /* Define how long the maximum amount of time the session can be inactive. */ 
    define("MAX_IDLE_TIME", 3); 
    
    function getOnlineUsers(){ 
    
    if ( $directory_handle = opendir( session_save_path() ) ) { 
    $count = 0; 
    while ( false !== ( $file = readdir( $directory_handle ) ) ) { 
    if($file != '.' && $file != '..'){ 
    // Comment the 'if(...){' and '}' lines if you get a significant amount of traffic 
    if(time()- fileatime(session_save_path() . '\\' . $file) < MAX_IDLE_TIME * 60) { 
    $count++; 
    } 
    } 
    closedir($directory_handle); 
    
    return $count; 
    
    } 
    }
    else { 
    return false; 
    } 
    
    } 
    
    echo '(' . getOnlineUsers() . ' viewer)<br />'; ?>
    
    </div>

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to have session_start() right at the top of the page.

    ie. <?php session_start(); ?> THEN <!DOCTYPE... etc

  3. #3
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,615
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    In order for a session to be started, no output can be sent to the browser yet. This also means that if you print out PHP error messages before session_start(), you'll get the same error as well.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,065
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    There is nothing wrong with the script as posted, I tried it locally and did not get any errors so possibly something is wrong with the OPs setup. co.ador is the script you posted in a include used by another file, if it is the culprit is most likely in the other file.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    There is nothing wrong with the script as posted, I tried it locally and did not get any errors so possibly something is wrong with the OPs setup.
    php has a feature which can buffer output for you.
    http://www.php.net/manual/en/ref.outcontrol.php

    This is probably turned on automatically in your configuration files.

  6. #6
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what is the OPs setup?

    Yes the script I have put is included in another file, is that the cause of the problem?

    I include that script in another file.

    What is the culprit?


    Hope this can be solved...

  7. #7
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Zend Framework utilizes the
    <?php
    //code goes here

    pattern, leaving the (?>) closing tag and its main purpose is to avoid the unecessary space outputs.

  8. #8
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    space outputs.

    I have downloaded the script and analyzed and i notice the ?> closing tag was missing. i thought they have don't a mistake so i put it back again.


    Well now with the ?> closing tags and the script code below this is the error that comes alone.

    Notice: Undefined variable: REMOTE_ADDR in C:\wamp\www\nyhungry\includes\header.php on line 62
    Useronline Insert Failed >
    Notice: Undefined variable: PHP_SELF in C:\wamp\www\nyhungry\includes\header.php on line 74
    0 users online
    ?>

    PHP Code:
    <?php 
    //fill in some basic info
    $server "localhost"
    $db_user "root"
    $db_pass "trementdo"
    $database "colo"
    $timeoutseconds 300

    //get the time
    $timestamp time(); 
    $timeout $timestamp-$timeoutseconds

    //connect to database
    mysql_connect($server$db_user$db_pass); 

    //insert the values
    $insert mysql_db_query($database"INSERT INTO useronline VALUES
    ('
    $timestamp','$REMOTE_ADDR'['REMOTE_ADDR'],'$_SERVER'['PHP_SELF']"); 
    if(!(
    $insert)) { 
    print 
    "Useronline Insert Failed > "


    //delete values when they leave
    $delete mysql_db_query($database"DELETE FROM useronline WHERE timestamp<$timeout"); 
    if(!(
    $delete)) { 
    print 
    "Useronline Delete Failed > "


    //grab the results
    $result mysql_db_query($database"SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'"); 
    if(!(
    $result)) { 
    print 
    "Useronline Select Error > "


    //number of rows = the number of people online
    $user mysql_num_rows($result); 


    //spit out the results
    mysql_close(); 
    if(
    $user == 1) { 
    print(
    "$user Hungry online\n"); 
    } else { 
    print(
    "$user users online"); 

    ?>
    If you notice i have changed the script a little bit.

  9. #9
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,065
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    You've got the ' in the wrong place:

    PHP Code:
    //insert the values
    $insert mysql_db_query($database"INSERT INTO useronline VALUES
    ('
    $timestamp','$REMOTE_ADDR'['REMOTE_ADDR'],'$_SERVER'['PHP_SELF']"); 
    if(!(
    $insert)) { 
    print 
    "Useronline Insert Failed > "

    should be:

    PHP Code:
    //insert the values
    $insert mysql_db_query($database"INSERT INTO useronline VALUES
    ('
    $timestamp','$REMOTE_ADDR['REMOTE_ADDR']','$_SERVER['PHP_SELF']'"); 
    if(!(
    $insert)) { 
    print 
    "Useronline Insert Failed > "

    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  10. #10
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I do it like you last suggested then this parse error come up

    Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\nyhungry\includes\header.php on line 55
    Then if I put curly braces then the following erros come alone.

    Useronline Insert Failed > Useronline Delete Failed > Useronline Select Error >
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\nyhungry\includes\header.php on line 74

    the three requests to the data base fail


    The Insert:

    PHP Code:
    //insert the values
    $insert mysql_query"INSERT INTO useronline VALUES
    ('
    $timestamp','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['PHP_SELF']}'" mysql_error()); 
    if(!(
    $insert)) { 
    print 
    "Useronline Insert Failed > " 

    The Delete:

    PHP Code:
    //delete values when they leave
    $delete mysql_query("DELETE FROM useronline WHERE timestamp<$timeoutmysql_error()); 
    if(!(
    $delete)) { 
    print 
    "Useronline Delete Failed > "

    The SELECT:

    PHP Code:
    //grab the results
    $result mysql_query("SELECT DISTINCT ip FROM useronline WHERE file='{$_SERVER['PHP_SELF']}'" mysql_error()); 
    if(!(
    $result)) { 
    print 
    "Useronline Select Error > "

    and as a result of not connection then mysql_num_rows fail too.

    PHP Code:
    //number of rows = the number of people online
    $user mysql_num_rows($result); 
    The error as I stated above is

    Useronline Insert Failed > Useronline Delete Failed > Useronline Select Error >
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\nyhungry\includes\header.php on line 74
    The connection i think is ok...


    The connection i have set up goes as follows

    it stars with including constant.php in connection.php

    constant.php

    PHP Code:
    <?php

    // Database Constants
    defined('DB_SERVER') ? null define("DB_SERVER""localhost");
    defined('DB_USER')   ? null define("DB_USER""username");
    defined('DB_PASS')   ? null define("DB_PASS""pass");
    defined('DB_NAME')   ? null define("DB_NAME""colo");

    ?>

    then in connection.php include constant.php. Inside connection.php I work the function mysql_connect

    Connection.php
    [code] <?php require("constant.php");
     
    $connection mysql_connect(DB_SERVER,DB_USER,DB_PASS);
    if(!
    $connection){
    die(
    "Database connection failed:" mysql_error());
    }
    Then the mysql_select_db function

    PHP Code:
    mysql_set_charset('utf8',$connection);
    $db_select mysql_select_db(DB_NAME$connection);
    if(!
    $db_select){
    die(
    "Database selection failed: " mysql_error());

    and finally the mysql_query functions which are three

    PHP Code:
    $insert mysql_query"INSERT INTO useronline VALUES
    ('
    $timestamp','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['PHP_SELF']}'" mysql_error()); 
    if(!(
    $insert)) { 
    print 
    "Useronline Insert Failed > " 



    //delete values when they leave
    $delete mysql_query("DELETE FROM useronline WHERE timestamp<$timeoutmysql_error()); 
    if(!(
    $delete)) { 
    print 
    "Useronline Delete Failed > "


    //grab the results
    $result mysql_query("SELECT DISTINCT ip FROM useronline WHERE file='{$_SERVER['PHP_SELF']}'" mysql_error()); 
    if(!(
    $result)) { 
    print 
    "Useronline Select Error > "

    Help please....

    is the connection alright?


Bookmarks

Posting Permissions

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