"Cannot modify header information" error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mikek12004
    New Member
    • Sep 2008
    • 200

    #1

    "Cannot modify header information" error

    In top of my index I include funcs.php which is :
    Code:
    <?php
    function GetCartId()
    {
    	//if user logged on use username as identification, else use coockie for anonymous user	
    	if ($_SESSION['loggedon']==1)
    	{
    	$a=$_SESSION['username'];
    	}			
    	else
    	{
    	// This part generates an encrypted string and will set it as a cookie using set_cookie. This will also be used as the cookieId    //field in the cart table
    		if(isset($_COOKIE["cartId"]))
    		{
    			return $_COOKIE["cartId"];
    		}
    		else
    		{
    			// There is no cookie set. We will set the cookie
    			// and return the value of the users session ID
    			
    			session_start();
    			setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
    			$a=session_id();
    			
    			
    		}
    	}
    	return $a;
    }
    function mssql_sec($a)
    {
    $a=str_replace("'","''",$a);
    $a=str_replace(";","",$a);
    return $a;
    }
    function mssql_sec2($a)
    {
    $a=str_replace("'","''",$a);
    //$a=str_replace(";","",$a);
    return $a;
    }
    ?>
    then later at the index I include basket.php which calls GetCartId() and the explorer shows the message
    "Cannot modify header information - headers already sent by (output started at /var/www/html/generalm/demo/index.php:31) in /var/www/html/generalm/demo/nimda/funcs.php on line 22"
    any help?
    PS before including the funcs.php I have sesion_start()
  • mikek12004
    New Member
    • Sep 2008
    • 200

    #2
    The whole point is to identify a user so I can recognise him in future visits, even if I get the error the func works and a unique id (which is $a) is retrived which I can use it to display various info for him, any idea how can I disable the stupid error and why since it works this error is diplayed?

    Comment

    Working...