I’m trying to make a login script that if the user checks the remember me option there information will be stored in a cookie if not then the information is stored in sessions i dont know that about about cookies in php i know the function for it just not how to use it.
@Jarrod1937Nov 06.2010 — #If the information being saved is possibly sensitive, then i'd recommend always using sessions to store their info, and instead have the "remember me" option simply change how long the cookie and session last (set no expiration time and the cookie is destroyed at the end of the session).
The cookies are automatically handled by php if you use their built in session system. However, if you want to manually set a cookie and its contents use setcookie(); (site is complete with explanation and examples).
function delete_all_cookies (path) { // Get cookie string and separate into individual cookie phrases: var cookie_string = "" + document . cookie; var cookie_array = cookie_string . split ("; ");
// Try to delete each cookie: for (var i = 0; i < cookie_array . length; ++ i) { var single_cookie = cookie_array [i] . split ("="); if (single_cookie . length != 2) continue; var name = unescape (single_cookie [0]); delete_cookie (name, path); } }
function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if (c_start!=-1) { c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) c_end=document.cookie.length; return unescape(document.cookie.substring(c_start,c_end)); } } return ""; }
@BelrickNov 07.2010 — #Also you may be interested in this little tip.
In the login exec.php you can have a bunch of reasons as to why the login will fail.
eg:
[code=php] $qry="SELECT * FROM users WHERE email = '$login' AND password='$password'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { //all good } else{ //no good header("location: login-form.php?reason=ne"); }
[/code]
So within the login form script above you can add this in the body
[code=php] <?php
@$reason=$_GET["reason"]; $message = " ";
switch ($reason){ case "ne": $message = "Sorry but we are having server issues, please try again later"; break; //Have as many failed to login errors you like from incorrect login or login already in use etc } ?>
echo $message; //Add this anywhere in the form page you like
[/code]
And now upon login failure you can display reasons why without a seperate login-failed.php page