Logging In
Moderator: General Moderators
Logging In
k Hi im just starting PHP!
Ive got all the code to log in to a website and so on, but im still confused how i would make the login text boxes not visible after login and make the users name and other stats appear on the same .php sheet.
Anyone got an idea how u make the contents change if an action is performed?
Ive got all the code to log in to a website and so on, but im still confused how i would make the login text boxes not visible after login and make the users name and other stats appear on the same .php sheet.
Anyone got an idea how u make the contents change if an action is performed?
yeah, just make if statements....
http://www.yoursite.com/login.php?success=yes
Now, if you have display errors on in your php.ini, youll get variable not defined, so you $success = $_REQUEST['success'] i believe.
http://www.yoursite.com/login.php?success=yes
Code: Select all
<?
if($success==yes) {
<-- your text here -->
} else {
include:("login.php");
}
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
actually should be
but oh well
Code: Select all
<?php
$success = ""; //initialize var
if (isset($_REQUEST["success"])) {
$success = $_REQUEST["success"];
}
if ($success==1) {
<--- text here --->
} else {
<---- text here --->
}
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
There is one major problem with that code - if I guess that you have a success variable and just pass 1 to it in the URL, then I end up logged in without any other validation.
Using sessions would be more secure:
Before Post Read: Sessions with a Minor in User Logins
Mac
Using sessions would be more secure:
Before Post Read: Sessions with a Minor in User Logins
Mac
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
I was pointing out the flaw in that method of deciding whether a user was logged in or not. I wouldn't want anybody to use that as part of their login system just because they don't understand the inherent problem.
I also wanted to point the OP to the sticky that we have specifically dealing with user logins.
Mac
I also wanted to point the OP to the sticky that we have specifically dealing with user logins.
Mac
-
PastAustin
- Forum Newbie
- Posts: 15
- Joined: Wed Jun 11, 2003 11:38 am
- Location: Littleton, Colorado
- Contact:
Well personally I am a cookies only man. Though sessions are nice, I have never been able to get used to them, plus they set cookies anyways.
adm: What exactly are you trying to hide. If you have text boxes you want to hide, you could do something like this:
Than your login function could look like this:
adm: What exactly are you trying to hide. If you have text boxes you want to hide, you could do something like this:
Code: Select all
<?php
if (!isSet($_COOKIE['cookiename'])) {
?>
<form method="post">
User | <input name="username"><br>
Password | <input type="password" name="password"><br>
<input type="submit" value="login">
</form>
<?php
} else {
?>
You are logged in!
<?php
}
?>Code: Select all
if (login info success) {
setcookie("cookiename", "dataincookie", time() + 7200);
}