SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot charles_i's Avatar
    Join Date
    Apr 2007
    Location
    Toronto, Canada
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Session question - disable each link after use

    I'm building a feedback site for past workshops. I have a page with a list of workshop titles which link to a feedback form. When the feedback form is completed it takes the user back to the workshop titles page - but at that point we want the link they just used to be disabled so they can keep choosing another one and not have to remember which workshop they already rated.

    Sounds to me like a PHP Sessions issue (as well as CSS for changing link colour) but I see a couple of differences in what I've read about Sessions.

    1) There is no login for username and password (these are anonymous ratings) so I need to develop another way of tracking - in fact IP number would work fine in this case.

    2) This is not a time based scenario. It's not a user who is logged in and will time out after a period of inactivity. It has to continue as one Session until they leave the website.

    Any articles or samples that would fit this case would be greatly appreciated.

    Charles

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Cookies

    setcookie
    Saul

  3. #3
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With the scenario you have laid out you have two alternatives. Either way you need to dynamically generate your menus.
    I used the first option in my web site, and that was to create my menus dynamically as list items. A little css and a function or two and I can generate menus in which I can disable a menu option and even gray the text out. I use it so that the link for the current page is disabled.
    You can always check the list of visited links in a session variable and if visited you can echo out underlined text instead of a hypertext link. A little css and no one will ever know it's not a real link.
    The second would be just not even have the link text echoed @ all if the link is in a session variable of visited links.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  4. #4
    SitePoint Zealot charles_i's Avatar
    Join Date
    Apr 2007
    Location
    Toronto, Canada
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the info. I'd think I should use Sessions rather than cookies because it only needs to track one use of the site - we're not concerned about people returning to it later.

    My current problem is how do I combine PHP and Javascript to input a form selection? When someone rates the workshop they have to choose from 1 to 5 but not leave the page as there are other questions to answer. I need to store the variable (number of choice) and send it with the submit button.

  5. #5
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use a function that onclick() sets the text value in a hidden field of the second form. Return = False on the form 1 submit button so that it does not actually submit. Then when the second form is sent the value will be in a hidden field.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  6. #6
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    # link builder
    if (count($_SESSION['feedback_link'] < count($linkarray)) {
            
    $newarray array_diff($linkarray$_SESSION['feedback_link']);
        foreach (
    $newarray as $v) {
              
    # output here, you would want to echo <option>
        
        
    }
    }

    # feedback handler
    # after processing the form based on the selected drop down menu
    $_SESSION['feedback_link'][] = $_POST['feedback_list']; 
    Something along this line?

  7. #7
    SitePoint Zealot charles_i's Avatar
    Join Date
    Apr 2007
    Location
    Toronto, Canada
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks but I decided just to go with radio buttons for that part. But the code from wonshikee looks close to what I need to track how many links were clicked on the previous page during this Session.

    In order to add each link on workshop.php to the array on feedback.php (so I can add the link name to the db table and change colour of the links used) do I need to create a separate db table to Post it to and then Get it each time? Also, does a Session have to be an integer? It doesn't work with the name of the link.

    Thanks


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
  •