SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 73 of 73

Thread: Sessions

  1. #51
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Parse error: parse error, unexpected T_VAR in C:\Documents and Settings\Neil\My Documents\www\template atm\membership.php on line 23

  2. #52
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    post ur lines of code here let us know line no. 23 as well

  3. #53
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Hey,


    Site Code:

    PHP Code:
    <?php

    //Define loggedin
    var $_SESSION['loggedin']; 

    //Define action
    var $_GET['action'];

    //$_SESSION['loggedin'] = 1; 




    if ($_GET['action'] == "")
    {
        if (
    $_SESSION['loggedin'] == 0)
        {
            echo 
    "Default Page"
        }
        else
        {
            echo 
    "Normal Page when Logged In";
        }           
    }

    if (
    $_GET['action'] == "login" )
    {
        if (
    $_SESSION['loggedin'] == 1)
        {
            echo 
    "Already Logged In Message";
        }
        else
        {
            echo 
    "Log in Form"
        
    }
    }

    if (
    $_GET['action'] == "register" )
    {
        if (
    $_SESSION['loggedin'] == 1)
        {
            echo 
    "Already logged in and registered message";
        }
        else
        {
            echo 
    "Registration Form";
        }





    ?>

    <!--New Lines-->
    <br /><br />
    <!--End New Lines-->
    Please note that the session start code is above the code i have posted.

    Line 23 is this line:

    PHP Code:
    var $_SESSION['loggedin']; 
    Thanks

    Neil

  4. #54
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    wht the o/p for this

    PHP Code:
    <?php

    error_reporting
    (0);

    if (
    $_GET['action'] == "")
    {
        if (
    $_SESSION['loggedin'] == 0)
        {
            echo 
    "Default Page";
        }
        else
        {
            echo 
    "Normal Page when Logged In";
        }           
    }

    if (
    $_GET['action'] == "login" )
    {
        if (
    $_SESSION['loggedin'] == 1)
        {
            echo 
    "Already Logged In Message";
        }
        else
        {
            echo 
    "Log in Form"
        
    }
    }

    if (
    $_GET['action'] == "register" )
    {
        if (
    $_SESSION['loggedin'] == 1)
        {
            echo 
    "Already logged in and registered message";
        }
        else
        {
            echo 
    "Registration Form";
        }
    }

    ?>

  5. #55
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try debuging ur self else this problem dont have any end, am not able to see ur complete code

  6. #56
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is my complete code, I basically have a php function above and below the code i posted which calls in the start html, with head and start body tag, layout and all that and the below function closes the layout div and ends the body and html stuff. - So why can't it be debugged as it is.

  7. #57
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whts the o/p of above code

  8. #58
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    o/p?

  9. #59
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    output of my code which i posted just above

  10. #60
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    wht kind of output u r getting after using following code :

    PHP Code:
    <?php

    error_reporting
    (0);

    if (
    $_GET['action'] == "")
    {
        if (
    $_SESSION['loggedin'] == 0)
        {
            echo 
    "Default Page";
        }
        else
        {
            echo 
    "Normal Page when Logged In";
        }           
    }

    if (
    $_GET['action'] == "login" )
    {
        if (
    $_SESSION['loggedin'] == 1)
        {
            echo 
    "Already Logged In Message";
        }
        else
        {
            echo 
    "Log in Form"
        
    }

    }

    if (
    $_GET['action'] == "register" )
    {
        if (
    $_SESSION['loggedin'] == 1)
        {
            echo 
    "Already logged in and registered message";
        }
        else
        {
            echo 
    "Registration Form";
        }
    }

    ?>
    b4 this ve u ever work vth PHP ?

  11. #61
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When using the code you posted i get an unexpected } error on line 45

    Line 45 is the middle line of:

    {
    echo "Log in Form"
    }

    }

    Thanks

    Neil

  12. #62
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh come on u can solve that by urself give a try b4 post here
    put a ; after echo and try again..........


    whenever u use session variable u need to start the session first am assuming that u r starting session on this file only or on some other file and including that file here or vice versa......................
    Last edited by simplecode; Jan 10, 2007 at 16:12.

  13. #63
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is that working ?

  14. #64
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll post the results tommorow and yes the session is beung started on anther page. which is being included

  15. #65
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    2morow y not now

  16. #66
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,
    Using that latest code, I view the page and it says Default Page. I'll just set the session to 1 and see what happens!

  17. #67
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, An Update!

    If i use

    $_SESSION['loggedin'] = 1;

    then the page shows "Normal Page when logged in" which is great - just as it was meat to do.

    I then commented out the error reporting line (As i DO want error reporting ON) and it still worked great!

    I will now add in the content i need in each area and will post here if anything else develops!

    Thanks

    Neil

  18. #68
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what happ??????

  19. #69
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What happened with what?

  20. #70
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nothing......
    its gr8 2 hear that finally its working.....

  21. #71
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Everything is working fine so far. Can you just let me know if this code is written right as "You are not logged in" seems to be showing all the time!

    PHP Code:
    if ($_GET['action'] == "logout" ){
     
        if (
    $_SESSION['loggedin'] == 1
        {
            unset(
    $_SESSION['username']);
            unset(
    $_SESSION['id']);
            unset(
    $_SESSION['loggedin']);
            
            echo 
    'Thanks for logging out. <a href="membership.php">Click here to go back to the membership system.</a>';
            
        }
    } else {

    echo 
    'You are not logged in';


    Thanks

    Neil

  22. #72
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if ($_GET['action'] == "logout" )
    if theis condition is true then echo 'You are not logged in'; will not get displayed but if if ($_GET['action'] != "logout" ) then it will come to else part

  23. #73
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if u want to show that message when user is not logged in do like this
    PHP Code:
    if ($_GET['action'] == "logout" )
    {
        if (
    $_SESSION['loggedin'] == 1)
        {
            unset(
    $_SESSION['username']);
            unset(
    $_SESSION['id']);
            unset(
    $_SESSION['loggedin']);
            
            echo 
    'Thanks for logging out. <a href="membership.php">Click here to go back to the membership system.</a>';
            
        }
        
    //assuming that action == logout means user is loggedout 
        
    echo 'You are not logged in';

    http://www.w3schools.com/php/php_if_else.asp
    try to learn from all post


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
  •