Jump to content

Recommended Posts

[code]
<?

/* $Id: Guid.php,v 1.0 2004/07/08 05:50:17 binzy Exp $ */

class System
{
    function currentTimeMillis()
    {
        list($usec, $sec) = explode(" ",microtime());
        return $sec.substr($usec, 2, 3);
    }

}

class NetAddress
{

    var $Name = 'localhost';
    var $IP = '127.0.0.1';
    
    function getLocalHost() // static
    {
        $address = new NetAddress();
        $address->Name = $_ENV["COMPUTERNAME"];
        $address->IP = $_SERVER["SERVER_ADDR"];

        return $address;
    }

    function toString()
    {
        return strtolower($this->Name.'/'.$this->IP);
    }

}

class Random
{
    function nextLong()
    {
        $tmp = rand(0,1)?'-':'';
        return $tmp.rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(100, 999).rand(100, 999);
    }
}


class Guid
{

    var $valueBeforeMD5;
    var $valueAfterMD5;

    function Guid()
    {
        $this->getGuid();
    }

    function getGuid()
    {
        $address = NetAddress::getLocalHost();
        $this->valueBeforeMD5 = $address->toString().':'.System::currentTimeMillis().':'.Random::nextLong();
        $this->valueAfterMD5 = md5($this->valueBeforeMD5);
    }

    function newGuid()
    {
        $Guid = new Guid();
        return $Guid;
    }

    function toString()
    {
        $raw = strtoupper($this->valueAfterMD5);
        return substr($raw,0,8).'-'.substr($raw,8,4).'-'.substr($raw,12,4).'-'.substr($raw,16,4).'-'.substr($raw,20);
    }

}

?>

<?php

if (!isset($_COOKIE['SessionID'])):
   $Guid = new Guid();
   setcookie('SessionID',$Guid->toString());
   echo $_COOKIE['SessionID'];    
else:
   echo $_COOKIE['SessionID'];
endif;

?>[/code]


I get an error like this -

[b]Warning: Cannot modify header information - headers already sent[/b]

Anyone, help please..

Thanks
Link to comment
https://forums.phpfreaks.com/topic/9690-a-little-help-needed-with-headers/
Share on other sites

Thanks for the quick reply...
But the error seems to have tripled...


[code]Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/www/test/guid.php:2) in /var/www/test/guid.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/test/guid.php:2) in /var/www/test/guid.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at /var/www/test/guid.php:2) in /var/www/test/guid.php on line 87[/code]

I put "session_start()" at the start of the php file..

[code]<?php session_start();
/* $Id: Guid.php,v 1.0 2004/07/08 05:50:17 binzy Exp $ */

class System
{
    function currentTimeMillis()

............
........
?>[/code]

Thanks
You can fix this by buffering your output.

[code]<?php
ob_start();
?>[/code]

Put this at the very top line of your script.

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]
you mean like this, right

[code]
<?php
ob_start();
session_start();

/* $Id: Guid.php,v 1.0 2004/07/08 05:50:17 binzy Exp $ */

class System
{
    function currentTimeMillis()
    {
....................................
....................................
....................................
....................................
?>[/code]

When i run the page, i get error like this:

[b]Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/www/test/guid.php:2) in /var/www/test/guid.php on line 4

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/test/guid.php:2) in /var/www/test/guid.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/test/guid.php:2) in /var/www/test/guid.php on line 88[/b]


Thanks
[code] <?php
ob_start();
session_start();
?>

<?php

/* $Id: Guid.php,v 1.0 2004/07/08 05:50:17 binzy Exp $ */

class System
{
    function currentTimeMillis()
    {
....................................
....................................
....................................
....................................
?>[/code]

Try it like this.

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]
[b]Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/www/test/guid.php:2) in /var/www/test/guid.php on line 4

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/test/guid.php:2) in /var/www/test/guid.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/test/guid.php:2) in /var/www/test/guid.php on line 92[/b]


Sorry, It didnt help...

Thanks
if you look closer to the error message, it mentions "output started at /var/www/test/guid.php:2". that suggest you might have blank lines before line 2. remove the blank lines and the session will work.

FYI: anything involving headers (header,cookie,session, etc) needs to be sent BEFORE any output.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.