apple
Sep 25 2006, 06:42 AM
This is a simple code to register and login.. this uses cookies.. i want to use sessions instead.. can someone tell how i can do it ? config.php CODE
<? ob_start(); // allows you to use cookies $conn = mysql_connect("localhost","USER","PASSWORD"); mysql_select_db(DATEBASE) or die(mysql_error()); //fill in the above lines where there are capital letters. $logged = MYSQL_QUERY("SELECT * from users WHERE id='$_COOKIE[id]' AND password = '$_COOKIE[pass]'"); $logged = mysql_fetch_array($logged); //the above lines get the user's information from the database. ?>
login.php CODE <? oB_start(); // allows you to use cookies. include("config.php"); if (!$logged[username]) { if (!$_POST[login]) { echo(" <center><form method=\"POST\"> <table> <tr> <td align=\"right\"> Username: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"username\"> </td> </tr> <tr> <td align=\"right\"> Password: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"password\"> </td></tr><tr> <td align=\"center\"> <input type=\"submit\" name=\"login\" value=\"Login\"> </td></tr><tr> <td align=\"center\"> <a href=\"register.php\">Register Here</a> </td></tr></table></form></center>"); } if ($_POST[login]) { // the form has been submitted. We continue... $username=$_POST['username']; $password = md5($_POST[password]); // the above lines set variables with the submitted information. $info = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error()); $data = mysql_fetch_array($info); if($data[password] != $password) { // the password was not the user's password! echo "Incorrect username or password!"; }else{ // the password was right! $query = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error()); $user = mysql_fetch_array($query); // gets the user's information setcookie("id", $user[id],time()+(60*60*24*5), "/", ""); setcookie("pass", $user[password],time()+(60*60*24*5), "/", ""); // the above lines set 2 cookies. 1 with the user's id and another with his/her password. echo ("<meta http-equiv=\"Refresh\" content=\"0; URL=http://www.djcazoo.sparknom.com/flexihabbo/home.php\"/>Thank You! You will be redirected"); // modify the above line...add in your site url instead of yoursite.com } } } else { // we now display the user controls. echo ("<center>Welcome <b>$logged[username]</b><br /></center> - <a href=\"editprofile.php\">Edit Profile</a><br /> - <a href=\"members.php\">Member List</a><br /> - <a href=\"logout.php\">Logout</a><br />"); } ?>
Reply
slu
Sep 25 2006, 08:04 AM
QUOTE(apple @ Sep 25 2006, 08:42 AM)  This is a simple code to register and login.. this uses cookies.. i want to use sessions instead.. can someone tell how i can do it ?
Your're confusing the terms a bit here. A session really isn't an alternative to using cookies. When using a session, the default behavior is to store the session using a cookie, which will happen automatically. Check out the documentation of start_session(), which you need to call to use sessions: http://dk2.php.net/manual/en/function.session-start.phpIf you don't want to rely on cookies at all, you either add the Session ID (SID) to all your urls/links or enable automatic url rewriting. You can read more about this here: http://www.zend.com/zend/tut/session.php?a...p;view=1#propag
Reply
Similar Topics
Keywords : sessions cookies- Something I Discovered With Sessions [php]
- (4)
- Php Sessions And Post Variables Issues
- My script dosent seem to work as intended (1)
You can test it out for yourself at http://sonesay.trap17.com/application.php I've been
working on this page locally and it seems to be working fine but when I upload it to my trap17
account the post variables dont get saved properly. Fill in some fields and submit it, the form
will come up as a empty field yet when you resubmit it without any modifications and the data you
entered in orginally will now magically appear, resubmit it again and it will be gone. This is
really annoying as I have no clue why it would be doing this when it seems to work fine locally....
Blank Cookies...
- Need some help with Cookies... (4)
Hi. I'm doing a website that basically checks if it has chosen a css style before. If it has, it
shows the last shown style, and if it doesn't, it shows "natura" style. On the page there's
a form that lets the user choose the style. It is based on cookies. The thing is that when I do java
script:alert(document.cookie) on the address bar it gives me a blank alert! And, obviously, when
I reload the page, the style doesn't change!!! The thing is I'm sure it has
nothing to do with the HTML code, and I also thing it does have nothing to do ...
<?php ?> Unique Visitors Script
- Flat file unique visitors script (no sessions) (2)
This is really simple script. Well at least this part is, but it could be extendable. Only problem
is that it's not really for massive websites with hundread of visitors a day, but rather for
small ones. But it is a good script to figure out how to make a visitor counter script. Anyway
here's the snippet. CODE <?php function getVisits($variable) {
$visits = array(); if ($handle =
opendir('stats/')) { while (false !== ($file =
readdir($handle))) { ...
<?php ?> Get Search Results To Your Localhost
- Simple way to get 100 results without allowing cookies (2)
Ultimately simple script that allows you getting google search results to your localhost. This is
the first part of the Crawler script i'm developing, and if you are interested in developing the
script with me, IM me @icq328866661@msn/evil_matak/ a \hotmail-com. Here's the form
part... QUOTE search.php QUOTE if (@$_POST ==""){ echo "What are you
doing?"; } else{ $query =
file_get_contents("http://www.google.com/search?q=".urlencode($_POST
)."&num=100&hl=en&ie=UTF-8&filter=2"); //needs to be added with more queries ...
Sessions And Login
- Without Cookies (5)
Hi, I have a login script i made using PHP sessions and MySQL. It works fine but there is a
problem. As you know Sessions are stored in Cookies by PHP. So if someone has switched Cookies off
then no sessions will work. How to solve this problem ? Please help me. Thanks and have a good
day. ...
Session Variables
- Sessions in PHP behaving strangely (4)
Hi. I am part of a development team working in PHP and MySQL. The site is using SSL, and users
have to log to use the site. When users log in, their important details are retrieved from the
database and stored in session variables (functionality in the site is permissions specific).
Lately, sessions are "disappearing" for no apparent reason. Users will log in, and at some point
(the length of time will vary unpredicatably) the sessions will lose their value (the variables are
empty) and this causes the site to evict the user. This is very frustrating for the user b...
Cookies
- How to make something like that? (1)
Can anybody help me? Im making new website and there will be needed such thing as login... so there
will be needed thing as cookies too. Can anybody please tell me how to make them and how and where
to use them? Alredy thanks, Dawiss...
Php Sessions
- Multiple users using the same login (2)
Hi, I'm realtively new to PHP and I'm considering creating some login functionality.
However I want a group of users to use the same loginname and password. They will be loggin infrom
different machines. The users will know they are sharing the account. Can anyone give me an idea
of what kind of effect this might have on my sessions? Will it create any odd hiccups or other
strange things?...
Sessions
- heeeelllllp!!!!!! (8)
Hi. Im making a flatfile chatroom. Ive been making it about a month because I dont understand the
sessions. When the user enters the room he/she has to enter a nickname. But when the user enters a
message the chatroom "forgets" the nickname. Ive been messing around with sessions but I cant get em
to work. Session_start(); thingy is in the right place (at the top). Ive looked through about 10
diferent tutorials but they were useless. How do I make it to pass the nickname variable to multiple
pages? And please dont tell me to search google or use php.net because ive alread...
Grrrr, Cookies Just Wont Work :(
- (2)
Ok i have tried many tutorials and all tell me to do this: setcookie("uname", $name,
time()+36000); But it always says: "Warning: Cannot modify header information - headers already
sent" They say to put it on the very first line with no spaces, which i do, like this: Im using
IIS with XP Pro, and have PHP 4.3 installed... why wont it work? /sad.gif' border='0'
style='vertical-align:middle' alt='sad.gif' /> **edit, wow i cant believe no one could answer this
EASY question, but after reading many documents, i figured out that i hadent declared the $name...
Looking for sessions, cookies
|
|
Searching Video's for sessions, cookies
|
advertisement
|
|