SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Sessions...

  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I need some help with sessions. Basically, I have a pop up, which they user should only see once and i want to use sessions for this. Houw would i do this.

    Just for refernce, Is there a way that I can also, use sessions, make a popup that submits to newsletters. If they submit then they never see the popup again however if they don't submit, of haven't submited another way, then in about 15 days they get another popup asking if they would like to join the newsletter. Is there a way to do this?

    Thanx for the help

    Peter

    P.S Does anyone know any great Session tutorials?

  2. #2
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it sounds like you need to be using cookies... not sessions.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    COuld anyone help me out with this then using PHP?

    Thanx

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [SHAMELESS SELF-PROMOTION]
    http://www.mycoding.com/tutorials.php?id=5
    [/SHAMELESS SELF-PROMOTION]

    That should help you get started with cookies. Beyond that, it's all pretty simple.

    Cookie are used to track data over large amounts of time...sessions are better used to track what a user does over the course of a single visit.

  5. #5
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Chris.

    I've read your article before however, what I'm not understanding is how to say that $shown variable in the cookie is value 1 after the visitor has recieved the popup.

    Here is my popup code:

    Code:
    <script langauge="javascript">
    function survey(url)
    { 
    surveywindow=window.open(url,'survey','width=500,height=550') 
    }
    </script>
    Then I use a <body onLoad="survey('survey.php')">

    --------------

    Now I'm guessing I put this at the top of my index page:

    PHP Code:
    <?
    $seen 
    $HTTP_COOKIE_VARS["shown"];
    if (
    $seen != ) {
    ?>
    <script langauge="javascript">
    function survey(url)

    surveywindow=window.open(url,'survey','width=500,height=550') 
    }
    </script>
    <?
    }
    ?>
    Now on my survey.php page, would I then create a cookie storing the value?

    PHP Code:

    <?
    setcookie 
    ("1"$showntime()+31536000); 
    ?>
    Is this how everything should work?

    Thanx

    Peter

  6. #6
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, A worked it out...i had allot messed up.

    In the main file i have:

    PHP Code:
    <?
    $seen 
    $HTTP_COOKIE_VARS["shown"];
    if (
    $seen != ) {
    $bodytag "onLoad=\"survey('survey.php')\"";
    }
    ?>

    <script langauge="javascript">
    function survey(url)
    { surveywindow=window.open(url,'survey','width=500,height=550') 
    }
    </script>
    <BODY <? echo $bodytag?>>

    Then in the survey.php file i have:

    PHP Code:
    <?
    $value 
    1;
    setcookie ("shown"$valuetime()+31536000); 
    ?>
    Thanx Chris for that one!

    Peter

  7. #7
    exit();
    Join Date
    Jul 2000
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, pretty simple concept

    Just a cookie and an if() statement

  8. #8
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL - sorry I wasn't here to reply earlier, but I'm sure you feel better having figured it out yourself. But yeah, you've got the idea. Might make it a bit longer than 2 weeks though...

  9. #9
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought i set it to a year?

    Did i?

    Well, I only need it for a month or two i think. Until i get enough responses to put together a nice little demographic report.

    Thanx

    Peter

  10. #10
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes you did set it to a year.
    3600*24*365 = 31536000


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
  •