Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: start session with javascript?

  1. #1
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default start session with javascript?

    Hello again guys, i need your assistance once again

    I just made a login application and I would like to start the php session but im not sure how to write php code in javascript the code I need to write in the javascript is this:
    Code:
    var start_cookies = '<?php setcookie("user",' + name + ', time()+3600) ?>';
    What im trying to do is to first create a login form when a person click on the login link, then the user submit his username and password. when its submitted ajax will check the name and then send back the info so I need to start the session within javascript.

    Edit:

    Title should be "start cookie with javascript?" and not "start session with javascript?"
    Last edited by Dennis_Gull; 07-17-2007 at 10:03 AM.

  2. #2
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Cookies are not sessions. Don't use cookies for authentication because they can easily be added by the client(web developer toolbar).

  3. #3
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Oh I mixed them up, I meant cookies.
    hmm what should I do then if I cant start cookies?
    Last edited by Dennis_Gull; 07-17-2007 at 08:07 AM.

  4. #4
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Of course you can create cookies, I just said don't.

    But here's something that you might find useful:
    http://www.quirksmode.org/js/cookies.html

  5. #5
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yeah I know but what should I do if I shouldn't use cookies?
    I never used sessions before but is it more secure?

    also is javascript cookies the same thing as the php cookies?

    Edit:
    apparently it was.. but still need advice on how to get a more secure login..
    Last edited by Dennis_Gull; 07-17-2007 at 11:50 AM.

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Cookies are stored for the user and given a name, and a value. via the same name, the cookie can be accessed by PHP, Javascript, Flash, and other methods.

    Sessions are much more secure, though more complex.

    Cookies aren't secure. They are best used for easily storing bits of data to save for a while, but that can be deleted... nothing crucial, certainly. (Nor should you save anything crucial with sessions as they do expire and clear after a while.)

    For example, you could store a language preference for that visit to your site in a cookie, etc.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    As djr33 said, sessions are more secured. Let's take this situation as an instance:

    each time someone logs in ... you set a cookie "logged" and display certain contents by checking if the cookie is set or not,
    now, with a special toolbar(the "Web developer's toolbar") for firefox, you can easily add a fake cookie(which seems to the browser as if the website has added it) which will easily show all your contents.

    and again, as djr33 said, sessions are kinda complex but once you get familiar with them, they can be a life saver.

  8. #8
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I read this on w3schools.com
    However, session information is temporary and will be deleted after the user has left the website. If you need a permanent storage you may want to store the data in a database.
    So heres my new question, it possible to do this within javescript?

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No. Sessions are stored server-side.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    bah, well there goes that..

    I could create a temp random number in the db and then send it back to javascript and then cookie the username and the temp random number.. and as soon as the person reload a page the php code would check for the cookie and then replace it with a session after I check the db if the random number and username check... anyways that would still mean I have to reload the page before the user is really logged in..

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
  •