Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: PHP Sessions

  1. #1
    Alex Francis
    Guest

    Default PHP Sessions

    It is a long time since I did any PHP coding but was asked to create a site
    recently using PHP. Naturally I used some code which I know is working on
    another site but I cannot get it to work on my test server which is running
    PHP5. I think the other site is running PHP4. I would be grateful if someone
    can help.

    Here is the error message
    Warning: session_register() [function.session-register]: Cannot send session
    cookie - headers already sent by (output started at
    C:\wamp\www\html\confirm_login.php:50) in C:\wamp\www\reqfiles\login.req.php
    on line 60

    Warning: session_register() [function.session-register]: Cannot send session
    cache limiter - headers already sent (output started at
    C:\wamp\www\html\confirm_login.php:50) in C:\wamp\www\reqfiles\login.req.php
    on line 60
    logingroup is

    he code for this is here, starting at line 57
    if ($logingroup=="administrator")
    {
    // Create a session value
    session_register ('loginID');
    session_register ('logname');
    session_register ('administrator');

    // give the sessions a name
    $_SESSION['loginID'] = $loginID;
    $_SESSION['logname'] = $logname;
    $_SESSION['administrator'] = $administrator;

    echo ("logingroup is  ");
    echo $_SESSION['administrator'];

    } elseif ($logingroup=="member")
    {

    // Create a session value
    session_register ('loginID');
    session_register ('logname');
    session_register ('member');

    // give the sessions a name
    $_SESSION['loginID'] = $loginID;
    $_SESSION['logname'] = $logname;
    $_SESSION['member'] = $member;

    echo ("logingroup is  ");
    echo $_SESSION['member'];

    }
    mysql_close ($link);
    }
    ?>


  2. #2
    =?iso-8859-1?Q?Chuck_=ABBeyondFusion=BB?=
    Guest

    Default Re: PHP Sessions

    The session code needs to be placed at the start of the page, above all
    else.

    You also appear to be missing a session start. That goes first before any
    other PHP code at the start of the page.

    --
    Chuck Joslin
    BeyondFusion.com - Your Fusion Community
    www.beyondfusion.com

    Register domain names at www.awavedomains.com
    "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    news:gujpc3$38r1@flsun90netnews01.netobjects.com.. .
    > It is a long time since I did any PHP coding but was asked to create a
    > site recently using PHP. Naturally I used some code which I know is
    > working on another site but I cannot get it to work on my test server
    > which is running PHP5. I think the other site is running PHP4. I would be
    > grateful if someone can help.
    >
    > Here is the error message
    > Warning: session_register() [function.session-register]: Cannot send
    > session cookie - headers already sent by (output started at
    > C:\wamp\www\html\confirm_login.php:50) in
    > C:\wamp\www\reqfiles\login.req.php on line 60
    >
    > Warning: session_register() [function.session-register]: Cannot send
    > session cache limiter - headers already sent (output started at
    > C:\wamp\www\html\confirm_login.php:50) in
    > C:\wamp\www\reqfiles\login.req.php on line 60
    > logingroup is
    >
    > he code for this is here, starting at line 57
    > if ($logingroup=="administrator")
    > {
    > // Create a session value
    > session_register ('loginID');
    > session_register ('logname');
    > session_register ('administrator');
    >
    > // give the sessions a name
    > $_SESSION['loginID'] = $loginID;
    > $_SESSION['logname'] = $logname;
    > $_SESSION['administrator'] = $administrator;
    >
    > echo ("logingroup is &nbsp;");
    > echo $_SESSION['administrator'];
    >
    > } elseif ($logingroup=="member")
    > {
    >
    > // Create a session value
    > session_register ('loginID');
    > session_register ('logname');
    > session_register ('member');
    >
    > // give the sessions a name
    > $_SESSION['loginID'] = $loginID;
    > $_SESSION['logname'] = $logname;
    > $_SESSION['member'] = $member;
    >
    > echo ("logingroup is &nbsp;");
    > echo $_SESSION['member'];
    >
    > }
    > mysql_close ($link);
    > }
    > ?>



  3. #3
    Alex Francis
    Guest

    Default Re: PHP Sessions

    Chuck, Thanks for the quick reply.
    I have a session start as the first line of my page, but I don't see how I
    can put the session register lines at the beginning before I have checked
    that the user name and password are correct. I am about to change the code
    to the one at http://www.phpeasystep.com/phptu/6.html but it isn't much
    different from mine.

    "Chuck «BeyondFusion»" <supportno@spambeyondfusion.com> wrote in message
    news:gujqmt$38r2@flsun90netnews01.netobjects.com.. .
    > The session code needs to be placed at the start of the page, above all
    > else.
    >
    > You also appear to be missing a session start. That goes first before any
    > other PHP code at the start of the page.
    >
    > --
    > Chuck Joslin
    > BeyondFusion.com - Your Fusion Community
    > www.beyondfusion.com
    >
    > Register domain names at www.awavedomains.com
    > "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    > news:gujpc3$38r1@flsun90netnews01.netobjects.com.. .
    >> It is a long time since I did any PHP coding but was asked to create a
    >> site recently using PHP. Naturally I used some code which I know is
    >> working on another site but I cannot get it to work on my test server
    >> which is running PHP5. I think the other site is running PHP4. I would be
    >> grateful if someone can help.
    >>
    >> Here is the error message
    >> Warning: session_register() [function.session-register]: Cannot send
    >> session cookie - headers already sent by (output started at
    >> C:\wamp\www\html\confirm_login.php:50) in
    >> C:\wamp\www\reqfiles\login.req.php on line 60
    >>
    >> Warning: session_register() [function.session-register]: Cannot send
    >> session cache limiter - headers already sent (output started at
    >> C:\wamp\www\html\confirm_login.php:50) in
    >> C:\wamp\www\reqfiles\login.req.php on line 60
    >> logingroup is
    >>
    >> he code for this is here, starting at line 57
    >> if ($logingroup=="administrator")
    >> {
    >> // Create a session value
    >> session_register ('loginID');
    >> session_register ('logname');
    >> session_register ('administrator');
    >>
    >> // give the sessions a name
    >> $_SESSION['loginID'] = $loginID;
    >> $_SESSION['logname'] = $logname;
    >> $_SESSION['administrator'] = $administrator;
    >>
    >> echo ("logingroup is &nbsp;");
    >> echo $_SESSION['administrator'];
    >>
    >> } elseif ($logingroup=="member")
    >> {
    >>
    >> // Create a session value
    >> session_register ('loginID');
    >> session_register ('logname');
    >> session_register ('member');
    >>
    >> // give the sessions a name
    >> $_SESSION['loginID'] = $loginID;
    >> $_SESSION['logname'] = $logname;
    >> $_SESSION['member'] = $member;
    >>
    >> echo ("logingroup is &nbsp;");
    >> echo $_SESSION['member'];
    >>
    >> }
    >> mysql_close ($link);
    >> }
    >> ?>

    >



  4. #4
    Alex Francis
    Guest

    Default Re: PHP Sessions

    Sorry about that I had mispelled session in the session start. Nearly
    working now.
    "Chuck «BeyondFusion»" <supportno@spambeyondfusion.com> wrote in message
    news:gujqmt$38r2@flsun90netnews01.netobjects.com.. .
    > The session code needs to be placed at the start of the page, above all
    > else.
    >
    > You also appear to be missing a session start. That goes first before any
    > other PHP code at the start of the page.
    >
    > --
    > Chuck Joslin
    > BeyondFusion.com - Your Fusion Community
    > www.beyondfusion.com
    >
    > Register domain names at www.awavedomains.com
    > "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    > news:gujpc3$38r1@flsun90netnews01.netobjects.com.. .
    >> It is a long time since I did any PHP coding but was asked to create a
    >> site recently using PHP. Naturally I used some code which I know is
    >> working on another site but I cannot get it to work on my test server
    >> which is running PHP5. I think the other site is running PHP4. I would be
    >> grateful if someone can help.
    >>
    >> Here is the error message
    >> Warning: session_register() [function.session-register]: Cannot send
    >> session cookie - headers already sent by (output started at
    >> C:\wamp\www\html\confirm_login.php:50) in
    >> C:\wamp\www\reqfiles\login.req.php on line 60
    >>
    >> Warning: session_register() [function.session-register]: Cannot send
    >> session cache limiter - headers already sent (output started at
    >> C:\wamp\www\html\confirm_login.php:50) in
    >> C:\wamp\www\reqfiles\login.req.php on line 60
    >> logingroup is
    >>
    >> he code for this is here, starting at line 57
    >> if ($logingroup=="administrator")
    >> {
    >> // Create a session value
    >> session_register ('loginID');
    >> session_register ('logname');
    >> session_register ('administrator');
    >>
    >> // give the sessions a name
    >> $_SESSION['loginID'] = $loginID;
    >> $_SESSION['logname'] = $logname;
    >> $_SESSION['administrator'] = $administrator;
    >>
    >> echo ("logingroup is &nbsp;");
    >> echo $_SESSION['administrator'];
    >>
    >> } elseif ($logingroup=="member")
    >> {
    >>
    >> // Create a session value
    >> session_register ('loginID');
    >> session_register ('logname');
    >> session_register ('member');
    >>
    >> // give the sessions a name
    >> $_SESSION['loginID'] = $loginID;
    >> $_SESSION['logname'] = $logname;
    >> $_SESSION['member'] = $member;
    >>
    >> echo ("logingroup is &nbsp;");
    >> echo $_SESSION['member'];
    >>
    >> }
    >> mysql_close ($link);
    >> }
    >> ?>

    >



  5. #5
    =?iso-8859-1?Q?Chuck_=ABBeyondFusion=BB?=
    Guest

    Default Re: PHP Sessions

    Alex,

    I do a login form that has the same page to gather the login/password.

    <form method="post" action="<? echo $_SERVER['PHP_SELF'] ?>">

    Code at the start of the page checks to see if those variables are set and
    validate against a database.

    If they do, session variables are set and the user is logged in. If not, the
    login form is displayed. Or if they've tried to login and failed, an error
    message is displayed.

    --
    Chuck Joslin
    BeyondFusion.com - Your Fusion Community
    www.beyondfusion.com

    Register domain names at www.awavedomains.com
    "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    news:gujs9i$38r3@flsun90netnews01.netobjects.com.. .
    > Chuck, Thanks for the quick reply.
    > I have a session start as the first line of my page, but I don't see how I
    > can put the session register lines at the beginning before I have checked
    > that the user name and password are correct. I am about to change the code
    > to the one at http://www.phpeasystep.com/phptu/6.html but it isn't much
    > different from mine.
    >
    > "Chuck «BeyondFusion»" <supportno@spambeyondfusion.com> wrote in message
    > news:gujqmt$38r2@flsun90netnews01.netobjects.com.. .
    >> The session code needs to be placed at the start of the page, above all
    >> else.
    >>
    >> You also appear to be missing a session start. That goes first before any
    >> other PHP code at the start of the page.
    >>
    >> --
    >> Chuck Joslin
    >> BeyondFusion.com - Your Fusion Community
    >> www.beyondfusion.com
    >>
    >> Register domain names at www.awavedomains.com
    >> "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    >> news:gujpc3$38r1@flsun90netnews01.netobjects.com.. .
    >>> It is a long time since I did any PHP coding but was asked to create a
    >>> site recently using PHP. Naturally I used some code which I know is
    >>> working on another site but I cannot get it to work on my test server
    >>> which is running PHP5. I think the other site is running PHP4. I would
    >>> be grateful if someone can help.
    >>>
    >>> Here is the error message
    >>> Warning: session_register() [function.session-register]: Cannot send
    >>> session cookie - headers already sent by (output started at
    >>> C:\wamp\www\html\confirm_login.php:50) in
    >>> C:\wamp\www\reqfiles\login.req.php on line 60
    >>>
    >>> Warning: session_register() [function.session-register]: Cannot send
    >>> session cache limiter - headers already sent (output started at
    >>> C:\wamp\www\html\confirm_login.php:50) in
    >>> C:\wamp\www\reqfiles\login.req.php on line 60
    >>> logingroup is
    >>>
    >>> he code for this is here, starting at line 57
    >>> if ($logingroup=="administrator")
    >>> {
    >>> // Create a session value
    >>> session_register ('loginID');
    >>> session_register ('logname');
    >>> session_register ('administrator');
    >>>
    >>> // give the sessions a name
    >>> $_SESSION['loginID'] = $loginID;
    >>> $_SESSION['logname'] = $logname;
    >>> $_SESSION['administrator'] = $administrator;
    >>>
    >>> echo ("logingroup is &nbsp;");
    >>> echo $_SESSION['administrator'];
    >>>
    >>> } elseif ($logingroup=="member")
    >>> {
    >>>
    >>> // Create a session value
    >>> session_register ('loginID');
    >>> session_register ('logname');
    >>> session_register ('member');
    >>>
    >>> // give the sessions a name
    >>> $_SESSION['loginID'] = $loginID;
    >>> $_SESSION['logname'] = $logname;
    >>> $_SESSION['member'] = $member;
    >>>
    >>> echo ("logingroup is &nbsp;");
    >>> echo $_SESSION['member'];
    >>>
    >>> }
    >>> mysql_close ($link);
    >>> }
    >>> ?>

    >>

    >



  6. #6
    =?iso-8859-1?Q?Chuck_=ABBeyondFusion=BB?=
    Guest

    Default Re: PHP Sessions

    I hear you. I can spell but otfen can't tpye.

    --
    Chuck Joslin
    BeyondFusion.com - Your Fusion Community
    www.beyondfusion.com

    Register domain names at www.awavedomains.com
    "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    news:gujsj7$38r4@flsun90netnews01.netobjects.com.. .
    > Sorry about that I had mispelled session in the session start. Nearly
    > working now.
    > "Chuck «BeyondFusion»" <supportno@spambeyondfusion.com> wrote in message
    > news:gujqmt$38r2@flsun90netnews01.netobjects.com.. .
    >> The session code needs to be placed at the start of the page, above all
    >> else.
    >>
    >> You also appear to be missing a session start. That goes first before any
    >> other PHP code at the start of the page.
    >>
    >> --
    >> Chuck Joslin
    >> BeyondFusion.com - Your Fusion Community
    >> www.beyondfusion.com
    >>
    >> Register domain names at www.awavedomains.com
    >> "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    >> news:gujpc3$38r1@flsun90netnews01.netobjects.com.. .
    >>> It is a long time since I did any PHP coding but was asked to create a
    >>> site recently using PHP. Naturally I used some code which I know is
    >>> working on another site but I cannot get it to work on my test server
    >>> which is running PHP5. I think the other site is running PHP4. I would
    >>> be grateful if someone can help.
    >>>
    >>> Here is the error message
    >>> Warning: session_register() [function.session-register]: Cannot send
    >>> session cookie - headers already sent by (output started at
    >>> C:\wamp\www\html\confirm_login.php:50) in
    >>> C:\wamp\www\reqfiles\login.req.php on line 60
    >>>
    >>> Warning: session_register() [function.session-register]: Cannot send
    >>> session cache limiter - headers already sent (output started at
    >>> C:\wamp\www\html\confirm_login.php:50) in
    >>> C:\wamp\www\reqfiles\login.req.php on line 60
    >>> logingroup is
    >>>
    >>> he code for this is here, starting at line 57
    >>> if ($logingroup=="administrator")
    >>> {
    >>> // Create a session value
    >>> session_register ('loginID');
    >>> session_register ('logname');
    >>> session_register ('administrator');
    >>>
    >>> // give the sessions a name
    >>> $_SESSION['loginID'] = $loginID;
    >>> $_SESSION['logname'] = $logname;
    >>> $_SESSION['administrator'] = $administrator;
    >>>
    >>> echo ("logingroup is &nbsp;");
    >>> echo $_SESSION['administrator'];
    >>>
    >>> } elseif ($logingroup=="member")
    >>> {
    >>>
    >>> // Create a session value
    >>> session_register ('loginID');
    >>> session_register ('logname');
    >>> session_register ('member');
    >>>
    >>> // give the sessions a name
    >>> $_SESSION['loginID'] = $loginID;
    >>> $_SESSION['logname'] = $logname;
    >>> $_SESSION['member'] = $member;
    >>>
    >>> echo ("logingroup is &nbsp;");
    >>> echo $_SESSION['member'];
    >>>
    >>> }
    >>> mysql_close ($link);
    >>> }
    >>> ?>

    >>

    >



  7. #7
    Alex Francis
    Guest

    Default Re: PHP Sessions

    Chuck,
    That gets a bit complicated for me, even when I was doing more PHP I always
    found the ['PHP_SELF'] a bit too much and found that I was better creating a
    new page for submitting everything. I know it is less efficient but I found
    it easier to follow.

    "Chuck «BeyondFusion»" <supportno@spambeyondfusion.com> wrote in message
    news:gujsv4$38r5@flsun90netnews01.netobjects.com.. .
    > Alex,
    >
    > I do a login form that has the same page to gather the login/password.
    >
    > <form method="post" action="<? echo $_SERVER['PHP_SELF'] ?>">
    >
    > Code at the start of the page checks to see if those variables are set and
    > validate against a database.
    >
    > If they do, session variables are set and the user is logged in. If not,
    > the login form is displayed. Or if they've tried to login and failed, an
    > error message is displayed.
    >
    > --
    > Chuck Joslin
    > BeyondFusion.com - Your Fusion Community
    > www.beyondfusion.com
    >
    > Register domain names at www.awavedomains.com
    > "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    > news:gujs9i$38r3@flsun90netnews01.netobjects.com.. .
    >> Chuck, Thanks for the quick reply.
    >> I have a session start as the first line of my page, but I don't see how
    >> I can put the session register lines at the beginning before I have
    >> checked that the user name and password are correct. I am about to change
    >> the code to the one at http://www.phpeasystep.com/phptu/6.html but it
    >> isn't much different from mine.
    >>
    >> "Chuck «BeyondFusion»" <supportno@spambeyondfusion.com> wrote in message
    >> news:gujqmt$38r2@flsun90netnews01.netobjects.com.. .
    >>> The session code needs to be placed at the start of the page, above all
    >>> else.
    >>>
    >>> You also appear to be missing a session start. That goes first before
    >>> any other PHP code at the start of the page.
    >>>
    >>> --
    >>> Chuck Joslin
    >>> BeyondFusion.com - Your Fusion Community
    >>> www.beyondfusion.com
    >>>
    >>> Register domain names at www.awavedomains.com
    >>> "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    >>> news:gujpc3$38r1@flsun90netnews01.netobjects.com.. .
    >>>> It is a long time since I did any PHP coding but was asked to create a
    >>>> site recently using PHP. Naturally I used some code which I know is
    >>>> working on another site but I cannot get it to work on my test server
    >>>> which is running PHP5. I think the other site is running PHP4. I would
    >>>> be grateful if someone can help.
    >>>>
    >>>> Here is the error message
    >>>> Warning: session_register() [function.session-register]: Cannot send
    >>>> session cookie - headers already sent by (output started at
    >>>> C:\wamp\www\html\confirm_login.php:50) in
    >>>> C:\wamp\www\reqfiles\login.req.php on line 60
    >>>>
    >>>> Warning: session_register() [function.session-register]: Cannot send
    >>>> session cache limiter - headers already sent (output started at
    >>>> C:\wamp\www\html\confirm_login.php:50) in
    >>>> C:\wamp\www\reqfiles\login.req.php on line 60
    >>>> logingroup is
    >>>>
    >>>> he code for this is here, starting at line 57
    >>>> if ($logingroup=="administrator")
    >>>> {
    >>>> // Create a session value
    >>>> session_register ('loginID');
    >>>> session_register ('logname');
    >>>> session_register ('administrator');
    >>>>
    >>>> // give the sessions a name
    >>>> $_SESSION['loginID'] = $loginID;
    >>>> $_SESSION['logname'] = $logname;
    >>>> $_SESSION['administrator'] = $administrator;
    >>>>
    >>>> echo ("logingroup is &nbsp;");
    >>>> echo $_SESSION['administrator'];
    >>>>
    >>>> } elseif ($logingroup=="member")
    >>>> {
    >>>>
    >>>> // Create a session value
    >>>> session_register ('loginID');
    >>>> session_register ('logname');
    >>>> session_register ('member');
    >>>>
    >>>> // give the sessions a name
    >>>> $_SESSION['loginID'] = $loginID;
    >>>> $_SESSION['logname'] = $logname;
    >>>> $_SESSION['member'] = $member;
    >>>>
    >>>> echo ("logingroup is &nbsp;");
    >>>> echo $_SESSION['member'];
    >>>>
    >>>> }
    >>>> mysql_close ($link);
    >>>> }
    >>>> ?>
    >>>

    >>

    >



  8. #8
    Alex Francis
    Guest

    Default Re: PHP Sessions

    Still Having problems with my sessions:
    Here is my code for my login page and for my main authorised page:
    session_start(); is not shown since it is on the first line of the page not
    with the rest of the code:
    I don't seem to be getting the sessions created. I put in line 2 in my
    authorised page to help debug and got this error message:
    Notice: Undefined variable: _SESSION in
    C:\wamp\www\reqfiles\allauthsession.req.php on line 2

    Login Page
    <?php

    //create short names from form information
    $userlogname = $_POST["userlogname"];
    $userlogpass = $_POST["userlogpass"];

    $encryptedpassword = md5($userlogpass);

    //capture ip address
    $ipaddress = getenv ("REMOTE_ADDR");
    $date = date("D d M,Y");
    $time = date("h:i:s a");

    $sql = " SELECT * FROM logintable WHERE userlogname='$userlogname' AND
    userpasswd='$encryptedpassword'";

    //$retid = mysql_db_query($dbname, $sql, $link);
    $opendb = mysql_select_db($dbname, $link) or die("Cannot select the
    database.<br>" . mysql_error());
    $retid = mysql_query($sql, $link);
    if (!$retid) { echo( mysql_error()); }
    else {

    while ($row = mysql_fetch_array($retid)) {
    $loginID = $row["loginid"];
    $logingroup = $row["authgroup"];
    $logname = $row["fullname"];
    }
    $num = mysql_num_rows($retid);
    // echo ("$num");

    if ($num==0){
    echo ("You have entered a wrong User Name or Password &nbsp; &nbsp; &nbsp;
    <A HREF='login.php'> Back to Login Page </A>");
    exit;
    }

    $query = "INSERT INTO userstable VALUES('0', '$loginID', '$logname',
    '$ipaddress', '$date', '$time')";

    //echo ("The query is: <BR>$query<P>\n");

    if (mysql_db_query ($dbname, $query, $link)){

    echo ("<P>$logname is now logged in with $logingroup privileges.</P>\n");
    echo ("<P><A HREF=\"authorised_only.php?id=$loginID\">Go to the Private
    Section</A><P>\n");
    }

    if ($logingroup=="administrator")
    {
    //Create session values
    $_SESSION['loginID'] = "$loginID";
    $_SESSION['logname'] = "$logname";
    $_SESSION['admin'] = "$logingroup";

    } elseif ($logingroup=="member")
    {

    // Create session values
    $_SESSION['loginID'] = '$loginID';
    $_SESSION['logname'] = '$logname';
    $_SESSION['member'] = '$logingroup';

    }
    mysql_close ($link);
    }
    ?>

    Authorised Page
    <?php
    //echo "User : ".$_SESSION["logname"];

    if((isset($_SESSION["admin"]))||(isset($_SESSION["member"])))
    {
    echo" <a href= ../html/logout.php>Logout</a> ";
    }
    else {
    echo("You are not authorised to view this page");
    echo ' <a href= ../html/login.php>Log in</a>' ;
    exit;
    }
    ?>

    Probably doing something stupid!!!!!!!!!!!!

    "Chuck «BeyondFusion»" <supportno@spambeyondfusion.com> wrote in message
    news:guk06g$38r7@flsun90netnews01.netobjects.com.. .
    >I hear you. I can spell but otfen can't tpye.
    >
    > --
    > Chuck Joslin
    > BeyondFusion.com - Your Fusion Community
    > www.beyondfusion.com
    >
    > Register domain names at www.awavedomains.com
    > "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    > news:gujsj7$38r4@flsun90netnews01.netobjects.com.. .
    >> Sorry about that I had mispelled session in the session start. Nearly
    >> working now.
    >> "Chuck «BeyondFusion»" <supportno@spambeyondfusion.com> wrote in message
    >> news:gujqmt$38r2@flsun90netnews01.netobjects.com.. .
    >>> The session code needs to be placed at the start of the page, above all
    >>> else.
    >>>
    >>> You also appear to be missing a session start. That goes first before
    >>> any other PHP code at the start of the page.
    >>>
    >>> --
    >>> Chuck Joslin
    >>> BeyondFusion.com - Your Fusion Community
    >>> www.beyondfusion.com
    >>>
    >>> Register domain names at www.awavedomains.com
    >>> "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    >>> news:gujpc3$38r1@flsun90netnews01.netobjects.com.. .
    >>>> It is a long time since I did any PHP coding but was asked to create a
    >>>> site recently using PHP. Naturally I used some code which I know is
    >>>> working on another site but I cannot get it to work on my test server
    >>>> which is running PHP5. I think the other site is running PHP4. I would
    >>>> be grateful if someone can help.
    >>>>
    >>>> Here is the error message
    >>>> Warning: session_register() [function.session-register]: Cannot send
    >>>> session cookie - headers already sent by (output started at
    >>>> C:\wamp\www\html\confirm_login.php:50) in
    >>>> C:\wamp\www\reqfiles\login.req.php on line 60
    >>>>
    >>>> Warning: session_register() [function.session-register]: Cannot send
    >>>> session cache limiter - headers already sent (output started at
    >>>> C:\wamp\www\html\confirm_login.php:50) in
    >>>> C:\wamp\www\reqfiles\login.req.php on line 60
    >>>> logingroup is
    >>>>
    >>>> he code for this is here, starting at line 57
    >>>> if ($logingroup=="administrator")
    >>>> {
    >>>> // Create a session value
    >>>> session_register ('loginID');
    >>>> session_register ('logname');
    >>>> session_register ('administrator');
    >>>>
    >>>> // give the sessions a name
    >>>> $_SESSION['loginID'] = $loginID;
    >>>> $_SESSION['logname'] = $logname;
    >>>> $_SESSION['administrator'] = $administrator;
    >>>>
    >>>> echo ("logingroup is &nbsp;");
    >>>> echo $_SESSION['administrator'];
    >>>>
    >>>> } elseif ($logingroup=="member")
    >>>> {
    >>>>
    >>>> // Create a session value
    >>>> session_register ('loginID');
    >>>> session_register ('logname');
    >>>> session_register ('member');
    >>>>
    >>>> // give the sessions a name
    >>>> $_SESSION['loginID'] = $loginID;
    >>>> $_SESSION['logname'] = $logname;
    >>>> $_SESSION['member'] = $member;
    >>>>
    >>>> echo ("logingroup is &nbsp;");
    >>>> echo $_SESSION['member'];
    >>>>
    >>>> }
    >>>> mysql_close ($link);
    >>>> }
    >>>> ?>




  9. #9
    =?iso-8859-1?Q?Chuck_=ABBeyondFusion=BB?=
    Guest

    Default Re: PHP Sessions

    Alex,

    Are you placing a session start at the top of each page a logged in user
    will have access to? You need to.

    --
    Chuck Joslin
    BeyondFusion.com - Your Fusion Community
    www.beyondfusion.com

    Register domain names at www.awavedomains.com
    "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    news:gusa0g$4ph2@flsun90netnews01.netobjects.com.. .
    > Still Having problems with my sessions:
    > Here is my code for my login page and for my main authorised page:
    > session_start(); is not shown since it is on the first line of the page
    > not with the rest of the code:
    > I don't seem to be getting the sessions created. I put in line 2 in my
    > authorised page to help debug and got this error message:
    > Notice: Undefined variable: _SESSION in
    > C:\wamp\www\reqfiles\allauthsession.req.php on line 2
    >
    > Login Page
    > <?php
    >
    > //create short names from form information
    > $userlogname = $_POST["userlogname"];
    > $userlogpass = $_POST["userlogpass"];
    >
    > $encryptedpassword = md5($userlogpass);
    >
    > //capture ip address
    > $ipaddress = getenv ("REMOTE_ADDR");
    > $date = date("D d M,Y");
    > $time = date("h:i:s a");
    >
    > $sql = " SELECT * FROM logintable WHERE userlogname='$userlogname' AND
    > userpasswd='$encryptedpassword'";
    >
    > //$retid = mysql_db_query($dbname, $sql, $link);
    > $opendb = mysql_select_db($dbname, $link) or die("Cannot select the
    > database.<br>" . mysql_error());
    > $retid = mysql_query($sql, $link);
    > if (!$retid) { echo( mysql_error()); }
    > else {
    >
    > while ($row = mysql_fetch_array($retid)) {
    > $loginID = $row["loginid"];
    > $logingroup = $row["authgroup"];
    > $logname = $row["fullname"];
    > }
    > $num = mysql_num_rows($retid);
    > // echo ("$num");
    >
    > if ($num==0){
    > echo ("You have entered a wrong User Name or Password &nbsp; &nbsp; &nbsp;
    > <A HREF='login.php'> Back to Login Page </A>");
    > exit;
    > }
    >
    > $query = "INSERT INTO userstable VALUES('0', '$loginID', '$logname',
    > '$ipaddress', '$date', '$time')";
    >
    > //echo ("The query is: <BR>$query<P>\n");
    >
    > if (mysql_db_query ($dbname, $query, $link)){
    >
    > echo ("<P>$logname is now logged in with $logingroup privileges.</P>\n");
    > echo ("<P><A HREF=\"authorised_only.php?id=$loginID\">Go to the Private
    > Section</A><P>\n");
    > }
    >
    > if ($logingroup=="administrator")
    > {
    > //Create session values
    > $_SESSION['loginID'] = "$loginID";
    > $_SESSION['logname'] = "$logname";
    > $_SESSION['admin'] = "$logingroup";
    >
    > } elseif ($logingroup=="member")
    > {
    >
    > // Create session values
    > $_SESSION['loginID'] = '$loginID';
    > $_SESSION['logname'] = '$logname';
    > $_SESSION['member'] = '$logingroup';
    >
    > }
    > mysql_close ($link);
    > }
    > ?>
    >
    > Authorised Page
    > <?php
    > //echo "User : ".$_SESSION["logname"];
    >
    > if((isset($_SESSION["admin"]))||(isset($_SESSION["member"])))
    > {
    > echo" <a href= ../html/logout.php>Logout</a> ";
    > }
    > else {
    > echo("You are not authorised to view this page");
    > echo ' <a href= ../html/login.php>Log in</a>' ;
    > exit;
    > }
    > ?>
    >
    > Probably doing something stupid!!!!!!!!!!!!
    >
    > "Chuck «BeyondFusion»" <supportno@spambeyondfusion.com> wrote in message
    > news:guk06g$38r7@flsun90netnews01.netobjects.com.. .
    >>I hear you. I can spell but otfen can't tpye.
    >>
    >> --
    >> Chuck Joslin
    >> BeyondFusion.com - Your Fusion Community
    >> www.beyondfusion.com
    >>
    >> Register domain names at www.awavedomains.com
    >> "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    >> news:gujsj7$38r4@flsun90netnews01.netobjects.com.. .
    >>> Sorry about that I had mispelled session in the session start. Nearly
    >>> working now.
    >>> "Chuck «BeyondFusion»" <supportno@spambeyondfusion.com> wrote in message
    >>> news:gujqmt$38r2@flsun90netnews01.netobjects.com.. .
    >>>> The session code needs to be placed at the start of the page, above all
    >>>> else.
    >>>>
    >>>> You also appear to be missing a session start. That goes first before
    >>>> any other PHP code at the start of the page.
    >>>>
    >>>> --
    >>>> Chuck Joslin
    >>>> BeyondFusion.com - Your Fusion Community
    >>>> www.beyondfusion.com
    >>>>
    >>>> Register domain names at www.awavedomains.com
    >>>> "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    >>>> news:gujpc3$38r1@flsun90netnews01.netobjects.com.. .
    >>>>> It is a long time since I did any PHP coding but was asked to create a
    >>>>> site recently using PHP. Naturally I used some code which I know is
    >>>>> working on another site but I cannot get it to work on my test server
    >>>>> which is running PHP5. I think the other site is running PHP4. I would
    >>>>> be grateful if someone can help.
    >>>>>
    >>>>> Here is the error message
    >>>>> Warning: session_register() [function.session-register]: Cannot send
    >>>>> session cookie - headers already sent by (output started at
    >>>>> C:\wamp\www\html\confirm_login.php:50) in
    >>>>> C:\wamp\www\reqfiles\login.req.php on line 60
    >>>>>
    >>>>> Warning: session_register() [function.session-register]: Cannot send
    >>>>> session cache limiter - headers already sent (output started at
    >>>>> C:\wamp\www\html\confirm_login.php:50) in
    >>>>> C:\wamp\www\reqfiles\login.req.php on line 60
    >>>>> logingroup is
    >>>>>
    >>>>> he code for this is here, starting at line 57
    >>>>> if ($logingroup=="administrator")
    >>>>> {
    >>>>> // Create a session value
    >>>>> session_register ('loginID');
    >>>>> session_register ('logname');
    >>>>> session_register ('administrator');
    >>>>>
    >>>>> // give the sessions a name
    >>>>> $_SESSION['loginID'] = $loginID;
    >>>>> $_SESSION['logname'] = $logname;
    >>>>> $_SESSION['administrator'] = $administrator;
    >>>>>
    >>>>> echo ("logingroup is &nbsp;");
    >>>>> echo $_SESSION['administrator'];
    >>>>>
    >>>>> } elseif ($logingroup=="member")
    >>>>> {
    >>>>>
    >>>>> // Create a session value
    >>>>> session_register ('loginID');
    >>>>> session_register ('logname');
    >>>>> session_register ('member');
    >>>>>
    >>>>> // give the sessions a name
    >>>>> $_SESSION['loginID'] = $loginID;
    >>>>> $_SESSION['logname'] = $logname;
    >>>>> $_SESSION['member'] = $member;
    >>>>>
    >>>>> echo ("logingroup is &nbsp;");
    >>>>> echo $_SESSION['member'];
    >>>>>
    >>>>> }
    >>>>> mysql_close ($link);
    >>>>> }
    >>>>> ?>

    >
    >



  10. #10
    Alex Francis
    Guest

    Default Re: PHP Sessions

    I had to place an ob start at th beginning. I have also used session start
    in case the production server is different from my test server.
    Thanks for your help, it is all coming back to me. (it must be an age thing
    it has got worse since I retired).
    "Chuck «BeyondFusion»" <supportno@spambeyondfusion.com> wrote in message
    news:gusg1s$4na5@flsun90netnews01.netobjects.com.. .
    > Alex,
    >
    > Are you placing a session start at the top of each page a logged in user
    > will have access to? You need to.
    >
    > --
    > Chuck Joslin
    > BeyondFusion.com - Your Fusion Community
    > www.beyondfusion.com
    >
    > Register domain names at www.awavedomains.com
    > "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    > news:gusa0g$4ph2@flsun90netnews01.netobjects.com.. .
    >> Still Having problems with my sessions:
    >> Here is my code for my login page and for my main authorised page:
    >> session_start(); is not shown since it is on the first line of the page
    >> not with the rest of the code:
    >> I don't seem to be getting the sessions created. I put in line 2 in my
    >> authorised page to help debug and got this error message:
    >> Notice: Undefined variable: _SESSION in
    >> C:\wamp\www\reqfiles\allauthsession.req.php on line 2
    >>
    >> Login Page
    >> <?php
    >>
    >> //create short names from form information
    >> $userlogname = $_POST["userlogname"];
    >> $userlogpass = $_POST["userlogpass"];
    >>
    >> $encryptedpassword = md5($userlogpass);
    >>
    >> //capture ip address
    >> $ipaddress = getenv ("REMOTE_ADDR");
    >> $date = date("D d M,Y");
    >> $time = date("h:i:s a");
    >>
    >> $sql = " SELECT * FROM logintable WHERE userlogname='$userlogname' AND
    >> userpasswd='$encryptedpassword'";
    >>
    >> //$retid = mysql_db_query($dbname, $sql, $link);
    >> $opendb = mysql_select_db($dbname, $link) or die("Cannot select the
    >> database.<br>" . mysql_error());
    >> $retid = mysql_query($sql, $link);
    >> if (!$retid) { echo( mysql_error()); }
    >> else {
    >>
    >> while ($row = mysql_fetch_array($retid)) {
    >> $loginID = $row["loginid"];
    >> $logingroup = $row["authgroup"];
    >> $logname = $row["fullname"];
    >> }
    >> $num = mysql_num_rows($retid);
    >> // echo ("$num");
    >>
    >> if ($num==0){
    >> echo ("You have entered a wrong User Name or Password &nbsp; &nbsp;
    >> &nbsp; <A HREF='login.php'> Back to Login Page </A>");
    >> exit;
    >> }
    >>
    >> $query = "INSERT INTO userstable VALUES('0', '$loginID', '$logname',
    >> '$ipaddress', '$date', '$time')";
    >>
    >> //echo ("The query is: <BR>$query<P>\n");
    >>
    >> if (mysql_db_query ($dbname, $query, $link)){
    >>
    >> echo ("<P>$logname is now logged in with $logingroup privileges.</P>\n");
    >> echo ("<P><A HREF=\"authorised_only.php?id=$loginID\">Go to the Private
    >> Section</A><P>\n");
    >> }
    >>
    >> if ($logingroup=="administrator")
    >> {
    >> //Create session values
    >> $_SESSION['loginID'] = "$loginID";
    >> $_SESSION['logname'] = "$logname";
    >> $_SESSION['admin'] = "$logingroup";
    >>
    >> } elseif ($logingroup=="member")
    >> {
    >>
    >> // Create session values
    >> $_SESSION['loginID'] = '$loginID';
    >> $_SESSION['logname'] = '$logname';
    >> $_SESSION['member'] = '$logingroup';
    >>
    >> }
    >> mysql_close ($link);
    >> }
    >> ?>
    >>
    >> Authorised Page
    >> <?php
    >> //echo "User : ".$_SESSION["logname"];
    >>
    >> if((isset($_SESSION["admin"]))||(isset($_SESSION["member"])))
    >> {
    >> echo" <a href= ../html/logout.php>Logout</a> ";
    >> }
    >> else {
    >> echo("You are not authorised to view this page");
    >> echo ' <a href= ../html/login.php>Log in</a>' ;
    >> exit;
    >> }
    >> ?>
    >>
    >> Probably doing something stupid!!!!!!!!!!!!
    >>
    >> "Chuck «BeyondFusion»" <supportno@spambeyondfusion.com> wrote in message
    >> news:guk06g$38r7@flsun90netnews01.netobjects.com.. .
    >>>I hear you. I can spell but otfen can't tpye.
    >>>
    >>> --
    >>> Chuck Joslin
    >>> BeyondFusion.com - Your Fusion Community
    >>> www.beyondfusion.com
    >>>
    >>> Register domain names at www.awavedomains.com
    >>> "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    >>> news:gujsj7$38r4@flsun90netnews01.netobjects.com.. .
    >>>> Sorry about that I had mispelled session in the session start. Nearly
    >>>> working now.
    >>>> "Chuck «BeyondFusion»" <supportno@spambeyondfusion.com> wrote in
    >>>> message news:gujqmt$38r2@flsun90netnews01.netobjects.com.. .
    >>>>> The session code needs to be placed at the start of the page, above
    >>>>> all else.
    >>>>>
    >>>>> You also appear to be missing a session start. That goes first before
    >>>>> any other PHP code at the start of the page.
    >>>>>
    >>>>> --
    >>>>> Chuck Joslin
    >>>>> BeyondFusion.com - Your Fusion Community
    >>>>> www.beyondfusion.com
    >>>>>
    >>>>> Register domain names at www.awavedomains.com
    >>>>> "Alex Francis" <alex@francisgreenock.co.uk> wrote in message
    >>>>> news:gujpc3$38r1@flsun90netnews01.netobjects.com.. .
    >>>>>> It is a long time since I did any PHP coding but was asked to create
    >>>>>> a site recently using PHP. Naturally I used some code which I know is
    >>>>>> working on another site but I cannot get it to work on my test server
    >>>>>> which is running PHP5. I think the other site is running PHP4. I
    >>>>>> would be grateful if someone can help.
    >>>>>>
    >>>>>> Here is the error message
    >>>>>> Warning: session_register() [function.session-register]: Cannot send
    >>>>>> session cookie - headers already sent by (output started at
    >>>>>> C:\wamp\www\html\confirm_login.php:50) in
    >>>>>> C:\wamp\www\reqfiles\login.req.php on line 60
    >>>>>>
    >>>>>> Warning: session_register() [function.session-register]: Cannot send
    >>>>>> session cache limiter - headers already sent (output started at
    >>>>>> C:\wamp\www\html\confirm_login.php:50) in
    >>>>>> C:\wamp\www\reqfiles\login.req.php on line 60
    >>>>>> logingroup is
    >>>>>>
    >>>>>> he code for this is here, starting at line 57
    >>>>>> if ($logingroup=="administrator")
    >>>>>> {
    >>>>>> // Create a session value
    >>>>>> session_register ('loginID');
    >>>>>> session_register ('logname');
    >>>>>> session_register ('administrator');
    >>>>>>
    >>>>>> // give the sessions a name
    >>>>>> $_SESSION['loginID'] = $loginID;
    >>>>>> $_SESSION['logname'] = $logname;
    >>>>>> $_SESSION['administrator'] = $administrator;
    >>>>>>
    >>>>>> echo ("logingroup is &nbsp;");
    >>>>>> echo $_SESSION['administrator'];
    >>>>>>
    >>>>>> } elseif ($logingroup=="member")
    >>>>>> {
    >>>>>>
    >>>>>> // Create a session value
    >>>>>> session_register ('loginID');
    >>>>>> session_register ('logname');
    >>>>>> session_register ('member');
    >>>>>>
    >>>>>> // give the sessions a name
    >>>>>> $_SESSION['loginID'] = $loginID;
    >>>>>> $_SESSION['logname'] = $logname;
    >>>>>> $_SESSION['member'] = $member;
    >>>>>>
    >>>>>> echo ("logingroup is &nbsp;");
    >>>>>> echo $_SESSION['member'];
    >>>>>>
    >>>>>> }
    >>>>>> mysql_close ($link);
    >>>>>> }
    >>>>>> ?>

    >>
    >>

    >



Posting Permissions

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