Results 1 to 10 of 10

Thread: Cookies

  1. #1
    Join Date
    Jun 2007
    Posts
    9

    Arrow Unanswered: Cookies

    what i want to be able to do is
    login to a network
    open a webrowser
    have the form detect, through cookies, the user name and password
    and use it to automatically log in
    doing this all in php language

    i know i have to start a session using this code
    ?
    session_start();

    if (!$PHPSESSID) {
    session_register('memname');
    session_register('password');
    } else if ((!$font_family) || (!$font_size)) {
    session_register('memname');
    session_register('password');
    }
    ?>

    but i dont know where to go from there

  2. #2
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Hold on a sec,

    do you want your program to log onto a network (via VPN perhaps?) open a web browser (impossible in PHP it's a scripting language) with the webpage you want in it. Autofill the username/password fields and "automagically" log in without someone even pressing a button?

  3. #3
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    If you are using cookies, which you said you were, you need to look at http://www.w3schools.com/php/php_cookies.asp.
    You didn't mention you needed sessions

  4. #4
    Join Date
    Jun 2007
    Posts
    9
    thats what i need it to do is login automaticalluy

    i know nothing about writing php code so i was not to sure i needed a session

  5. #5
    Join Date
    Jun 2007
    Posts
    9
    the program it self just has the login on the webpage automatically

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so to auto login you need to set and read a cookie from a browser

    that measn your users have to be prepared to accept cookies, but you also have to cater for browsers which don't have a cookie (this may be the first time they have visitied the site, or they may not allow you to place cookies on their machine, or this may be the forst time they have visited since the did some housekeeping on their machine and cleared out the cookies.

    you can get round the cookie limitation to a certain extent in php using session variables, but that isn't going to cater for the users visiting the site afte the last session expired.

    Id expect you to have a single script....
    the first thing it should do is reqeust the specific cookie...
    then check the data in the cookie..
    if its valid target the script on the site that handles whatever
    if its invalid then you need to generate some HTML which requests a userid & password, and/or registration. how you handle that is up to you.

    you then need some other validation code somewhere to check the userid & password combination is valid (if they have supplied that, and/or you need some code to ensure their registration data is valid. Personally that sounds to me like several different classes in several different scripts (I prefer to have a single script to do a single function.. it simplifies the developers life). if you are web 1, if you are targeting web 2 then a judicious use of AJAX may reduce the number of scripts, and improve the user experience.

    If you application contains sensitive data then I wouldn't be keen on having no password authentication of a user based on a cookie. even if you encrypt the cookie userid it can probably still be faked through other means by a determined or lucky enough hacker. remember if some of the information in an encrypted data stream is known it makes it easier to decrypt.

    So if you want to store a cookie then by all means store the userid, but Id always request the password as part of a startup script. bear in mind that unless you know every user of your site will only ever logon on from their own terminal, and that no user shares their terminal with someone else..... a 'ferisntance' say you had an adult content site, would you want any user to auto logon without requesting a password.... say one of your users had young children in the family who could access the computer unsupervised, would you want your user account to be immediately activated without some password being requested, same goes say for other sites)
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Jun 2007
    Posts
    9
    thats exactly what i wanted to do there is a slight problem though i dont know how to write php so im stuck as how to manipulate the code to do what i want

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by Midnightskys1023
    thats exactly what i wanted to do there is a slight problem though i dont know how to write php so im stuck as how to manipulate the code to do what i want
    ..in which case I suggest
    ..you find some web resources that teach or train you in PHP (php.net is pretty good if you are coming from a developer background and have a rough idea of what you want to do). w3schools is perhaps a bit better for the total newbie
    ..you could find a local college or php user group which may be able to help
    ..you could find a couple of PHP books that give you a helping hand

    ..but this site is not there to help you learn PHP, its here to help with database related problems within PHP. its not intended to be a learn form scratch resource.. its intended (as I understand) as a mechanism of providing help and assistance to resolve specific problems, act as a sounding board to sort out those knotty development issues, or to assist in a specific detailed technical area.

    you are liable to get a better response if you make an effort and then request help where you are experiencing a specific limited problem.

    just saying
    ..."though i dont know how to write php code"..isnt going to elicit much sympathy as it seems like you want a off the shelf solution, which may or may not exist.... I find people tend to respond pretty helpfully if you try to do something and request help on that specific limited issue.

    so over to you
    try to find some usefull learning resources, try to understand the basic concepts behind PHP, how it works etc... write a few noddy programs / scripts which do soemthign and start on that learnign approach. incidentally I dont think the PHP has a particularly steep learning curve (its one of its advantages (you can get working code quite quickly) and one of its drawback (you can get crap code thats hard to maintian quite quickly [as I know to my cost with my early stuff])

    if youa re starting out on the learning process then use as recent a copy of PHP as possible (PHP5 has some real neat features), but bear in mind that you should develop int he same version of PHP as your target webserver users. It would be a waste of time to develop in PHP5 if the web server you intend using uses PHP3 or PHP4. developing an impressive class structure usnign inheritance and polymorphism falls apart at the seems if you try to deploy it on PHP4.

    good luck
    I'd rather be riding on the Tiger 800 or the Norton

  9. #9
    Join Date
    Jun 2007
    Posts
    9
    thanks alot

  10. #10
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    I would have to concur with healdem. Check out some PHP resources (php.net) and head off to w3cschools.com to get a headstart.

    By the brief description you're looking at using $_SESSION to maintain username/password login information (after login) and cookies for storing a username on each users local machine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •