Sessions ... The killer ... The bane of PHP menu

User Tag List

Results 1 to 11 of 11
  1. #1
    Spatz21's Avatar Active Member CoreCoins Purchaser
    Reputation
    15
    Join Date
    Nov 2007
    Posts
    208
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sessions ... The killer ... The bane of PHP

    Lets face it the hardest thing with PHP is ... Sessions. No one can ever get these to work first time, if they do they suddenly stop working. So, I am going to simplify to idiots level.

    Introduction

    A Session is a SUPER GLOBAL VARIABLE. This means that you can enter some data and call it after F5ing the page or after loading 1000 differen't pages. Aslong as you don't overwrite it ofc

    This is good for when you want to collect multiple pages of data, good for making someone an account with your site (It can store the users ID, this then gets passed from page to page, which can be used to call data from the database for that ID) etc ...


    The Actual Code

    to use/create/pass along sessions the code

    session_start()

    MUST BE AT THE START OF EVERY PAGE. Before any HTML. If not it will just error.

    At the top of every page I just put <?php session_start() ?> at the top of every page before everything else, on line 1.



    Putting data into session
    Pretty easy but alot of people get stuck on it!

    If you got your form ...
    <html>
    <form method=post action=blah.com>
    <input type=text name=UserID>
    <input type=submit>
    </form>
    </html>

    And your next page is just going to be where you stick your data into the session

    <?php session_start()
    //Now to create the session which you want to store data in. You can call ID what ever.
    $_SESSION['ID'] = $_POST['UserID'];
    ?>

    And finally the test to see if it worked(A third page)

    <?php session_start()
    print("$_SESSION['ID']");
    ?>

    Easy as ...

    You can use the $_SESSION['ID'] in mysql querys and all over your page if you wish. If you are making a site which requires a login you can make sure there is something in the session, otherwise back to home page.

    Deleting a session

    Usually the server that your hosting on will delete sessions created after a certain amount of time. Lets say if you dont need to use that session anymore and you don't want it interfering with users reusing your site you can use the command

    Session_destroy ()

    This will delete any sessions. Use for a log out script or if the values of data that were stored in the session are no longer needed ...




    I really, really, hope I explained this well and if you have any questions to ask go for it.

    I wish I had a stupidly simple guide like this when starting sessions but all I could find was a 10 page + guide ... pfft why read all that when it could be cut down so simply?
    Last edited by Spatz21; 03-20-2008 at 07:01 PM. Reason: My gramah and speeling is aweful ;)
    6 rep to -1
    Matt linking post in sbawx.. could've been -25 rep, read the rules

    Sessions ... The killer ... The bane of PHP
  2. #2
    warsheep's Avatar Contributor
    Reputation
    184
    Join Date
    Sep 2006
    Posts
    1,216
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    True, sessions can really create allot of trouble when reading hard guides. Mostly because they make everything more difficult!

    Good guide, I guess.
    +Rep
    FOR A MOMENT, NOTHING HAPPENED. THEN, AFTER A SECOND OR SO, NOTHING CONTINUED TO HAPPEN.

  3. #3
    Spatz21's Avatar Active Member CoreCoins Purchaser
    Reputation
    15
    Join Date
    Nov 2007
    Posts
    208
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried to simplify it as heavily as posible while explaining it at the same time
    6 rep to -1
    Matt linking post in sbawx.. could've been -25 rep, read the rules

  4. #4
    warsheep's Avatar Contributor
    Reputation
    184
    Join Date
    Sep 2006
    Posts
    1,216
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would rep, but I repped ya to recently :/
    FOR A MOMENT, NOTHING HAPPENED. THEN, AFTER A SECOND OR SO, NOTHING CONTINUED TO HAPPEN.

  5. #5
    tttommeke's Avatar Banned
    Reputation
    1
    Join Date
    Jul 2007
    Posts
    613
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sessions are easy xD cookies are weird :s

  6. #6
    Spatz21's Avatar Active Member CoreCoins Purchaser
    Reputation
    15
    Join Date
    Nov 2007
    Posts
    208
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guess I could do cookies next when I have the time
    6 rep to -1
    Matt linking post in sbawx.. could've been -25 rep, read the rules

  7. #7
    Sirupsen's Avatar Member
    Reputation
    25
    Join Date
    Oct 2007
    Posts
    260
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I miss information about the lasting of a session, and more examples of what you can use it for. (For "Who's online list" etc etc. So the new coders know why they are good.) And information about how long how much time in minutes it takes before it get's automaticly deleted? And that it get's deleted when you close your browser.



  8. #8
    Spatz21's Avatar Active Member CoreCoins Purchaser
    Reputation
    15
    Join Date
    Nov 2007
    Posts
    208
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Session lasts untill its destroyed, times out by the server or edited.

    How long it times out is set by the server. If your hosting on someone elses server you will need to contact them about it, if its your server you will just have to have alook around. It is not destroyed when you close your browser, its destroyed when you reopen your browser and your browser sends out a ping saying "Are you there", something like that but I am not too sure on that one.

    When I made a whose online list ... I am yet to learn how to access hosts sessions. I have only been using paid hosting servers. I just made it so everytime someone makes a click it records the time you made the click. If your last click on the site was less than 15 mins ago ... show as active


    My guide was generally a begginers guide that wasn't going to be too complex.
    6 rep to -1
    Matt linking post in sbawx.. could've been -25 rep, read the rules

  9. #9
    Pragma's Avatar Contributor
    Reputation
    261
    Join Date
    Feb 2007
    Posts
    630
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really needed a guide like this +Rep


  10. #10
    Sirupsen's Avatar Member
    Reputation
    25
    Join Date
    Oct 2007
    Posts
    260
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Gizzer View Post
    Session lasts untill its destroyed, times out by the server or edited.

    How long it times out is set by the server. If your hosting on someone elses server you will need to contact them about it, if its your server you will just have to have alook around. It is not destroyed when you close your browser, its destroyed when you reopen your browser and your browser sends out a ping saying "Are you there", something like that but I am not too sure on that one.

    When I made a whose online list ... I am yet to learn how to access hosts sessions. I have only been using paid hosting servers. I just made it so everytime someone makes a click it records the time you made the click. If your last click on the site was less than 15 mins ago ... show as active


    My guide was generally a begginers guide that wasn't going to be too complex.
    Well, okay. I knew about that stuff. But just I'm quite sure some people might be intrested in it?



  11. #11
    Runez's Avatar Member
    Reputation
    6
    Join Date
    Mar 2008
    Posts
    96
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Definetly worth mentioning session expiration and the likes.

    If theres anyone who want a "cookies guide" and you dont have time to do it anytime soon post it here and ill write one.

Similar Threads

  1. [Model Reskin] The Killer Sheep Returns
    By deadca7 in forum World of Warcraft Model Editing
    Replies: 15
    Last Post: 05-27-2008, 12:30 PM
  2. Fool's Bane ---> Maladath, Runed Blade of the Black Flight
    By Farek in forum WoW ME Questions and Requests
    Replies: 14
    Last Post: 09-29-2007, 11:33 AM
  3. Login theme to Read My Mind (The Killers)
    By LesloBrown in forum World of Warcraft Model Editing
    Replies: 9
    Last Post: 06-19-2007, 05:40 PM
  4. Addon To The Php Login Scam
    By paulgreen73 in forum WoW Scam Prevention
    Replies: 3
    Last Post: 06-11-2007, 04:09 PM
  5. Gruul the dragon killer exploit
    By Holysymbol in forum World of Warcraft Exploits
    Replies: 6
    Last Post: 04-07-2007, 12:02 AM
All times are GMT -5. The time now is 07:43 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search