Hello all I have spent all day looking through here and trying t ofigure out sessions and cookies. No I am confused...

Here is what I have.

PHP Session support is enabled on my server.

On the top of all my main pages not the includes I have this.

 
<?
session_start();
Print "Username is: " . $_COOKIE['UserName'] . "<BR>". chr(13); 
Print "UserID is: " . $_COOKIE['UserID'] . "<BR>" . chr(13); 
?>

I copied the above from another post in these forums.

From what I have gathered that is using a cookie and not a session.

Here is what I would like. I close out my browser go back to my website and now the Username and UserID are blank....I want to store a cookie so I know the user has come back. To show who is online. No need to logon each time the user comes back.

Here is how I give them the information for Username and userID.

<?
session_start();
setcookie("UserName",$logon); 
setcookie("UserID",$email); 
Print "Username is: " . $_COOKIE['UserName'] . "<BR>". chr(13); 
Print "UserID is: " . $_COOKIE['UserID'] . "<BR>" . chr(13); 
?>

This is on the LOGON page and the registerconfirm page.

What am I doing wrong how to I set it the other way? Am I trying to use sessions????

A side not since this is my first time messing with cookies what should I use for each individual cookie to identify them???? WOuld it be user name password?

Any sugestions to point me in the right direction would be appreciated.

I have read the following article with some hlp from it.

http://www.developers-resources.com/stories/02/10/15/9335730

If someone can get me a starting point I can hopefully work my way through this.

Thanks again.
Attila

OOOppps forgot something can I use an include or require once to an external PHP file for my cookie information?

    you can use cookies for "remembering" data during a visit to your site.

    or, you can use sessions, which use cookies themselves (in the background), and are more comfortable.

    if you choose sessions, you don't have to mess with $_COOKIE or setcookie().

    instead of setting a cookie using setcookie(), you register an existing variable to the session with session_register("variablename"); (this stores the variable with its current content in the session)

    for reading it out, instead of $COOKIE, you take $SESSION.

    and, sessions require being started (session_start).

    hope this helps a bit.

      Yes that helps and confuses me a little.

      Let me explain what I want and maybe you can advise me on what way to go.

      Person A goes to my website and has never been their before. They decide to register and upon registering they will be allowed to see all the pages a non registered person can't see. So when they register I go to a confirmation page that they have registered and that is when the cookie is set or the session is registered. I want the cookie or session to last the entire time they are there no experation time.

      Now person A closes his browser and comes back another day I want to be able to identify that person A is registered and have his name in a who's online list. Almost like who is online in a forum. I do not want them to have to register again.

      That is the basics but now lets get deeper to try and safeguard the person's account I will set 2 cookie variables or what ever you want to call it. Both those sessions or cookie data is saved to the database and verified when that person comes back. Then I will have the first cookie becomoe the second cookie and the second cookie become the first cookie. To keep swapping them around. Or just delete there origional cookie send them a new one and create a second one for the database. Not sure if this can be done.

      So what am I looking at as an easier sessions or cookies?

      Also can I use an inclued to call my session or cookie information? I understand it needs to be the first line of the page.

      Thanks,
      attila

      P.S. I am trying to create a portal system...I know many people have told me to jsut go get a free version but how am I to learn anything off a free version.....Their coding is either way to advanced for me or just so garbled up it is not easy to read.

        Well what you are trying to do.. can make many things happen

        what i did was make a function which

        checked if the session or cookies users was not empty (!empty)

        if it wasnt then update the page there on time etc

        if it was empty then register a session.

        Now if you want you can get from the sessions cookies etc to perform things for you..

        Say if the cookie users exists then we can print Username - else we leave it blank..

        Now in your case of getting User A when he closes hes window..
        Well try just using cookies its the best option.. But then again not everyone is comfortable with cookies being stored on there computer so when they sign up make a little input bit were it has remember me or something and if checked then they get cookie stored else session is registered. and they have to login everytime...

        If you want more help just reply

          I follow you compleatly so Cookies is the way to go. Give user option of having a cookie. Simple..

          Problem....Can you give me a starting place I have looked at so many differen things I am lost now as how to start.

          this is what i am thinking for a cookie.

          
          setcookie("GnA Squad", $logon, "0", "http://www.glorynaspiration.com", "glorynaspiration.com", "");
          
          

          $logon = logon+email+something else????

          How do I do this...I know it is asking alot but would greatly be appreciated.

          you can see the webpage I am working on at
          Glory and Aspiration

          Non of the logon pages are vissable to everyone else while I am working on them.

          Thanks,
          Attila

            Write a Reply...