Results 1 to 3 of 3

 

Thread: new session or old?

  1. #1
    Registered User

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    661
    Thanks
    0
    Thanked 0 Times in 0 Posts


    I'm writing a PHP script that will appear on every page of my site. I want to start a new session when a new visitor arrives at the site and output messageA, however if that vistor isn't new and a session already exists I want to output messageB.

    So far the only way I can find of determining whether a session has been started or not is by accessing a stored session variable, surely there is more tidy way than this?

    PHP Code:
    session_start();
    if(
    $_SESSION['myvarb'])
    {
    echo 
    "welcome back";
    }

    else {
    echo 
    "first time here";
    $_SESSION['myvarb'] = 1;

    Any help pointers gratefully recieved.

  2. #2
    futureweb's Avatar
    Registered User

    Status
    Offline
    Join Date
    Jul 2005
    Location
    North Devon
    Posts
    919
    Thanks
    13
    Thanked 22 Times in 22 Posts
    We don't even care what its value is becauase we are wild !

    PHP Code:
    session_start();
    if(isset(
    $_SESSION['MySession'])){
     
    // fire message b
    echo $messageB;
    }else{
    // set the session var
    $_SESSION['MySession'] = 1;
    // then fire message a
    echo $messagea;

    or the other way

    PHP Code:
    session_start();
    if(!isset(
    $_SESSION['MySession'])){
    // set the session var
    $_SESSION['MySession'] = 1;
    // then fire message a
    echo $messagea;
    }else{
     
    // fire message b
    echo $messageB;


  3. #3
    Registered User

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    661
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Futureweb

    I was hoping to do it without ever having to access the session variables, but I can't see how it's possible.

    I did try using $session_id, but that wouldn't work. Something along these lines:

    PHP Code:
    session_start(); 
    if(!
    $session_id){ 
    // set the session var 
    $_SESSION['MySession'] = 1
    // then fire message a 
    echo $messagea
    }else{ 
     
    // fire message b 
    echo $messageB




Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. php session login pages not hidden
    By Wardy in forum Programming
    Replies: 3
    Last Post: 16-08-06, 01:26 PM
  2. Dabs session cookie only
    By shopandsave in forum TradeDoubler
    Replies: 3
    Last Post: 13-09-03, 05:20 AM
  3. Session ID in link ?
    By aly in forum Programming
    Replies: 2
    Last Post: 24-06-03, 12:44 AM

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
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2