Welcome Guest ( Log In | Register)



2 Pages V   1 2 >  
Reply to this topicStart new topic
> <?php ?> Sloppy Login Script, Sloppy login script, couse i used @ on one string
Rating 1 V
matak
post Jun 1 2007, 08:53 AM
Post #1


Super Member
*********

Group: Members
Posts: 413
Joined: 4-October 06
From: Psychedelic Realms
Member No.: 31,079



Here's a sloppy 3 files login script. First file is Login file that looks like this

login.php
CODE
<form action="check.php" method="post">
Username: <input type="text" name="username1"><br />
Password: <input type="password" name="password1"><br />
<input type="submit" value="Login">
</form>


Basicly that is HTML form that's used for input

Second part of the script is the check.php that we call from our login.php form

QUOTE
<?php
//array that contains usernames and passwords
$userpass = array ("user1" => "123456");
//script that validates usernames and passwords
if ( array_key_exists($_POST['username1'], $userpass)
&&
$userpass[$_POST['username1']] == $_POST['password1']
)

{
session_start();
//part which redirects to page if username and password are correct
$_SESSION['user'] = $_POST['username1'];
$_SESSION['pass'] = $_POST['password1'];
echo "<a href=\"toview.php\">Registered Users Page</a>";
}
else {
//part that redirects to index.php or register.php
echo "Please register!<br />";
echo "<a href=\"login.php\">How to Register</a>";
}
?>


Third part is toview.php, which we are loging in to.
QUOTE

<?php session_start();

@$approve = $_SESSION['user'];

if ($approve == NULL):
echo "Please register!<br />";
echo "<a href=\"login.php\">How to Register</a>";
else:

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title></title>

</head>
<body>
<?php echo 'Welcome '.$_SESSION['user']; ?>
</body>
</html>
<?php endif; ?>


I call it sloppy couse this @ in code

QUOTE
@$approve = $_SESSION['user'];


is used to disable error reporting, which is generated if $approve variable isn't set. That error apears only if user directly tries to reach toview.php part, and if $_SESSION is NULL we don't approve that, and just echo the login PHP part.

Hope u find this useful

mAtAk
Go to the top of the page
 
+Quote Post
galexcd
post Jun 12 2007, 05:16 AM
Post #2


Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
***********

Group: [HOSTED]
Posts: 1,189
Joined: 25-September 05
From: Los Angeles, California
Member No.: 12,251
myCENT:39.85



I use @ all the time to keep from error reporting. Sure it's sloppy but nobody will know and the best part is that it works! laugh.gif
Go to the top of the page
 
+Quote Post
Blessed
post Jun 12 2007, 06:37 PM
Post #3


Advanced Member
*******

Group: Members
Posts: 144
Joined: 22-March 07
Member No.: 40,472



Greetings

nice script you have here m8,
you can inprove it by adding cooies to it,
so it remember the member the next time he is on you page,
you can even define the amount of hours of days / weeks he can stay logged

i can help you with that if you want,

feel free to pm me biggrin.gif

have a nice day biggrin.gif
Go to the top of the page
 
+Quote Post
matak
post Jun 12 2007, 10:52 PM
Post #4


Super Member
*********

Group: Members
Posts: 413
Joined: 4-October 06
From: Psychedelic Realms
Member No.: 31,079



QUOTE(Blessed @ Jun 12 2007, 08:37 PM) *
nice script you have here m8,
you can inprove it by adding cooies to it,
so it remember the member the next time he is on you page,
you can even define the amount of hours of days / weeks he can stay logged

i can help you with that if you want,

feel free to pm me biggrin.gif

have a nice day biggrin.gif


why PM ? ohmy.gif

It would be really great to work on it here, so all users can see it. Maybe togeather we could create a good login script. I never used cookies before.

Btw, do you know a way to use sessions, so that user doesn't have to turn cookies on. On my localhost i used Session and i don't usualy have cookies allowed, so it didn't work for me until i allowed cookies for localhost.

I'm interested in server side sessions, so that session is stored on server instead on your local computer.

Do you know how to do it?

@alex7h3pr0gr4m3r

I heard a lot that using @ means that your' sloppy programmer. But i didn't know how to handle this better (and without using isset wink.gif )
Go to the top of the page
 
+Quote Post
galexcd
post Jun 14 2007, 06:42 PM
Post #5


Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
***********

Group: [HOSTED]
Posts: 1,189
Joined: 25-September 05
From: Los Angeles, California
Member No.: 12,251
myCENT:39.85



Well I dont use the $session variable at all. When I make my login scripts I write my own session scripts with it. It may take longer but there is no need for sloppy coding.
Go to the top of the page
 
+Quote Post
sonesay
post Jun 21 2007, 08:19 AM
Post #6


|||[ n00b King ]|||
*********

Group: [HOSTED]
Posts: 715
Joined: 20-June 07
From: Auckland
Member No.: 45,102
myCENT:20.20



QUOTE(alex7h3pr0gr4m3r @ Jun 15 2007, 06:42 AM) *
Well I dont use the $session variable at all. When I make my login scripts I write my own session scripts with it. It may take longer but there is no need for sloppy coding.


Hi, I just want to ask what do you mean you dont use $session variable at all. do you mean you dont use $_SESSION[''] at all and store the users data by other means? If so could you explain how you do it your way? thanks.
Go to the top of the page
 
+Quote Post
matak
post Jun 21 2007, 01:34 PM
Post #7


Super Member
*********

Group: Members
Posts: 413
Joined: 4-October 06
From: Psychedelic Realms
Member No.: 31,079



QUOTE(sonesay @ Jun 21 2007, 10:19 AM) *
Hi, I just want to ask what do you mean you dont use $session variable at all. do you mean you dont use $_SESSION[''] at all and store the users data by other means? If so could you explain how you do it your way? thanks.


you don't need to use session if you check for the login in the same file you try to login to.. but that is weird way couse everytime when you try to view that page you would need to reenter your username and password.

and how does alextheprogrammer do that

"Write his own session scripts"

I also want to see an example rolleyes.gif
Go to the top of the page
 
+Quote Post
madrasboss
post Jul 31 2007, 02:42 AM
Post #8


Newbie [Level 1]
*

Group: Members
Posts: 14
Joined: 24-July 07
From: jamaica
Member No.: 46,964



QUOTE(matak @ Jun 21 2007, 01:34 PM) *
you don't need to use session if you check for the login in the same file you try to login to.. but that is weird way couse everytime when you try to view that page you would need to reenter your username and password.

and how does alextheprogrammer do that

"Write his own session scripts"

I also want to see an example rolleyes.gif


can that work on any site
Go to the top of the page
 
+Quote Post
matak