Qbasicnews.com

Full Version: yet another possilbly annoying PHP question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Well, being the php noob that i am, i was wondering if anyone can explain to me how to implement cookies....i know the general stuff, but im not sure how to go about it....all it has to contain is a username/id number.....either one will do

everypage will access it

Oz~
Look up $_COOKIE in the php.net documentation. It's not tremendously hard to do, but you have to remember to either use buffering, or to use the code before you send HTML headers.
You may want to include something else. Or encrypt it or soemthing. Becuase you can change your cookies. So all you need to do is change it to be someone else if you do it your way.
so how about putting their user id# and md5()ed password.

Sound good?

Oz~
don't store passwords in cookies, it's relatively safe (MD5 is still impossibly difficult to crack), but POOR practice (in case someone finds a fruitful way to decipher it)

instead, store a randomly generated hash based on the username and time ( pseudo: md5($username + $time) ) every time the user accesses a page. Store that hash in the cookie instead. a bit more secure if you understand what i just said.

Also, for actual creation of cookies:
setcookie(variablename, contents, EXPTIME);

To access the data in that cookie, use the cookie superglobal:
$variablename = $_COOKIE['variablename'];

All of this is in the PHP.NET manual (look up SETCOOKIE), one of the best resources for learning how to do this kind of stuff.
Instead of cookies you may want to use sessions. Sessions are server side stuff and hence inherently more secure. Look up $_SESSION for more info at php.net.
http://www.webhostingchat.com/forum/show...php?t=3977

This thread may interest you, it me asking the exactly the same question.
I did look into sessions, but they are way over my head......i just don't get them at all....i undertand some of the absolute basics on them, but I'd only learn them if it were absolutely required

Oz~
session works just like cookie, if one's over your head, so is the other.

just put a session_start() at the beginning of every page, and you can access $_SESSION superglobals.

ie. page1.php

session_start();
$_SESSION['username'] = "potato";

----------------------------------------------
page2.php

session_start();
if($_SESSION['username']) echo $_SESSION['username']; else echo "not logged in";

-----------------------------------------------
it's just a way to carry variables over pages, like $_POST data that doesn't need to be posted every time. It's different from cookie because it saves the data on the server side temporarily instead of longterm on the client side.
aliright...i understand now......i just need simple code examples that focus on one thing......that got it :bounce:

Now, if i wanted to use require, is ther a way that i can make it a small, size-contained scroll thing?

Oz~
Pages: 1 2 3