SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    including a session verification

    I know how to check if a sesson is there for instance:
    PHP Code:
    if(isset($_SESSION['user']))
    {
       
    //do this
    }
    else
    {
       
    //print not logged in

    But how do I include it in a header file for instance:
    PHP Code:
    include "session.php";
    //type text here if user is logged in 
    Just by including that and then typing text under it, it should only show the text if the user is logged in. I've tried all sorts of things, but I always get some kind of parse error, help!

  2. #2
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I usually do:

    PHP Code:
    include 'login_check.php';

    echo 
    "Congrats, you're in!"
    And in login_check:

    PHP Code:
    include 'globals.php';
    include 
    'redirect.php';

    if (!isset(
    $_SESSION['username'])) {
       
    redirect ("login.php");
       exit(); 
    //This is important, incase the browser 
                //doesn't redirect...

    My name is Steve, and I'm a super-villian.

  3. #3
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do

    PHP Code:
    if (!isset($_SESSION['user']))
    {
        die (
    'you are not logged in');

    that will end the script if a user is not logged in.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  4. #4
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys, you are a great help as always.


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
  •