1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Usage of PHP $_SESSION for HTML forms

Discussion in 'PHP' started by Hefaistos, Oct 28, 2013.

  1. #1
    Hi,
    My skills are not very advanced in php, and I'm currently working on a page that will allow users to complete some informations into 4 steps. Everything is ok, but I'm not usually use PHP $_SESSION and all I want to know is that if is ok to store some data into a session and than retrive it for a further step.
    Can somehow users encounter problems in usage of that script for various web hosts?
    SEMrush
     
    Solved! View solution.
    Hefaistos, Oct 28, 2013 IP
    SEMrush
  2. #2
    Hi Hefaistos,

    Sure you can.
    On my website for example when the user logins I query the database and store his data in a $_SESSION array, to avoid having to query the database at every page he views.
    Session support is enabled in PHP by default, I have never come across a host that doesn't support them, it would be a really strange hosting service.

    Hope this helps,
     
    monkeye, Oct 28, 2013 IP
    Hefaistos likes this.
  3. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #3
    its either SESSION or COOKIES, difference would be, data in cookies will be stored in the client.
     
    bartolay13, Oct 29, 2013 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,630
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    It's SESSIONS. Cookies can, for one, be manipulated by the client (much harder to do with sessions), cookies have a limited amount of space (normally not an issue, but the length of a cookie can't exceed a certain length) - while sessions doesn't really have that problem. If you need to store some temporary data, do use sessions.
     
    PoPSiCLe, Oct 29, 2013 IP
  5. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    612
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    4
    #5
    You can use sessions to store it from page to page that's simple enough if that's all you need it to do is temp store while they're at your site.
    If you'd like it to be retrieved if they come back at another time though...you can store to database OR even to a simple file/folder system.
    If they fill out their first and last name (and if the data isn't anything private /personal/legal) and works ALSO if you don't need them to sign-up as members with user names etc. Instead a write to .txt file can be created and the .txt file created can be concatenated as $last_name . "_" . $first_name;
    and by entering their name when they come back again it can grab the info again. (not secure way, not for members/sign-up/etc)
    It's not good to use $ip anymore since IPs aren't static and change all the time now for most.

    Depending on your site theme you could also make a graphic image of a number panel (like an ATM / security door) and they enter a number they choose when they filled out your form. When they return they punch in the number and it retrieves their info stored. Give them two tries and time them out so somebody isn't sitting punching in numbers all day to see what they can get out of it. Or a text box "what is last name?" ..and Panel ="enter your code"
    and store files as text file name = $lastname . "_" . $code;
    example: Shmoe_123456.txt
    inside file is all their info from the form. (not to be used on sensitive info ..not exactly secure at all)
    but makes a cool ATM panel theme
     
    ezprint2008, Oct 30, 2013 IP
  6. Hefaistos

    Hefaistos Active Member

    Messages:
    194
    Likes Received:
    14
    Best Answers:
    9
    Trophy Points:
    63
    Digital Goods:
    1
    #6
    Thank you all for replies. I'll use a session just to keep some temporary data from one step to another, before inserting it into the database. Also this session will not hold sensitive informations like passwords, but just some simple things like a post id and few others little things.
     
    Hefaistos, Oct 30, 2013 IP