![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
Login Problem
ok i have this and it works
[php] <?php include("./backend/config.php"); $username = $_POST['username']; $password = md5($_POST['password']); $ip = $_SERVER['REMOTRE_ADDR']; if($_REQUEST['do'] == 0){ if(isset($_POST['submit'])){ session_start(); $q = "SELECT * FROM user WHERE username='$username' AND password='$password' LIMIT 1"; $findmember = mysql_query($q); $rows = mysql_num_rows($findmember); if($rows > 0){ setcookie("username", $username, time()+(60*60*24*5), "/", "$ip"); setcookie("password", $password, time()+(60*60*24*5), "/", "$ip"); $_SESSION['username'] = $username; print(" ".$_COOKIE['username']." You have successfully logged in!"); print("Click <a href=\"user.php?username=".$_SESSION['username']."\">here</a>"); }else{ print("Username or password is invalid. Please try again!"); } } } [/php] I don't really want to use session but rather use cookies but im having trouble. like on this code [php] print("Click <a href=\"user.php?username=".$_SESSION['username']."\">here</a>"); [/php] I want to use this [php] print("Click <a href=\"user.php?username=".$_COOKIE['username']."\">here</a>"); [/php] I know that it doesn't set the value to $_COOKIE til the next page or so i heard. But the other thing like. I want to check for the verfication like if that user suppose to be in that area by member level and also if theres a way i don't have to rely on session but rather cookies. I want to force cookies. I forgot what i was going to say next but ill reply when I get it. if i can use cookies without session how would they be called so i can use them? |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Obviously, a cookie can't be set until you respond to the browser with the page, and it can't be retrieved until the browser contacts you with a new request. It's the nature of the paradigm.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Programmer
|
Then how do I retrieve the infomation from the cookie and use that for the script.
And I deleted my cookies after I ran the script and I successfully logged in but when I tried it again it continued to say invalid when I used the same name again? |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|