Web Analytics Made Easy -
StatCounter Create Session - CodingForum


No announcement yet.

Create Session

  • Filter
  • Time
  • Show
Clear All
new posts

  • Create Session


    I have a form for a user to fill in and send the data to a php page which will insert the data into a MySQL database.

    I would like to create a session for the user and insert the session is into the database along with the other values that the user specified. Once the data has been inserted I would like the session to expire so they cannot hit the back button and re-submit the form.

    Any ideas on how to do this? I've searched the web but no joy.

  • #2
    actually you dont want the session to expire

    set a unique id as your session value

    PHP Code:
    if( !isset( 
    $_SESSION['submitted'] ) ){
    $_SESSION['submitted'] = uniqidmktime() ) ;
    now check the database for the value of $_SESSION['submitted'] before you enter anything in , if that session id does not exist then they can insert.
    better still make the session_id field in the database unique and it will be ignored silently (check mysql_error() to see what happened)

    Now that wont stop anyone from closing all browsers and revisiting your site as the session is now lost , but you can also set a cookie with that session_id as well which will persist longer (for those with cookies enabled)

    &b4 anyone mentions it , you can't rely on the IP !
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)