PHP sessions - is this possible?

Discussion in 'PHP' started by gluedup2, Jun 28, 2007.

  1. #1
    In brief:
    A website with 5 pages. (index1.php, index2.php,... index5.php)

    Traffic goes to each of the 5 pages from PPC via tracking urls.
    -- this format: /index3.php?keyword={keyword}&adgroup=ABC1

    All 5 pages interlink each other so a visitor can browse the entire site. Every page has a form.

    Each bit of tracking data is assigned a variable and placed into form fields so where they came from is added into my database when they submit the form.
    echo $keyword , echo $adgroup .. etc.

    What I need:
    I need a session to begin when a user lands on the page and wherever they browse the tracking data will stick to their session and enter itself into the form on each page.
    I'd like to remove the need for every link on the site to have the tracking data on the end (?keyword=xx&adgroup=xx ..and so on).
    I want all links to be plain index3.php types (clean links)

    The problem:
    As each page needs code to start a NEW session in which it defines the variables from the tracking URL, when a user clicks a 'clean link' the next page will try and start a new session with non-existent data for the variables.


    I'm a PHP novice and know very little on sessions but found a script that stores the session in a database, it certainly worked but only for the first page the visitor lands on. Is what I'm after possible?

    I can't see a way around being able to define variables from an original tracking URL and letting them visit non-tracking urls (that themselves are trying to begin a session).
     
    gluedup2, Jun 28, 2007 IP
  2. TimAtchley

    TimAtchley Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    gluedup2,

    I'll give this a shot for a solution.

    To solve your problem with having session_start() on every page, I would create try "try(session_start());" I'm not positive that will work but give it a shot :).

    As far as getting rid of tags in your url, on your forms you are summitting information with, make it a _POST form instead of a _GET form. To retreive your information do

    if($_POST['keyword']!="")
    $_SESSION['keyword']=$_POST['keyword'];

    I'm not sure if this was exactly what you needed but I hope it helps.

    Tim
     
    TimAtchley, Jun 28, 2007 IP
  3. KalvinB

    KalvinB Peon

    Messages:
    2,787
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Use named sessions. Each page just needs to have it's own unique name and you're done.
     
    KalvinB, Jun 28, 2007 IP