Page 1 of 1
Need Help With a Login SCRIPT!!
Posted: Tue Oct 29, 2002 2:34 pm
by austin0369
Hey guys, maybe you can help me out, I really really..need it!
I am making a username/password login for my website, and we have Client-Logins, however, right now I have the username and passwords just written into the php.. FOr example:
<?
if($username == test && $password == test1);
{
echo("(HTML CODES GO HERE FOR THERE CERTAIN WESBITE. IN OTHER WORDS I PUT THE HTML INSIDE THE SCRIPT. PROVLEM WITH THIS IS IN THE FUTURE IT WILL BE TO BIG AND HARD TO EDIT)Welcome test!");
}
if($username == test2 && $password == test3);
{
echo("Welcome test2!")
}
If i messed up, sorry Im trying to type this as fast as i can. Basically im putrting the HTML coding in the PHP and I dont want to have to do that, how do i set it up so it takes it to a certain site, and so they CAnt just go back to that site without logging in? THanks in advance!
sessions
Posted: Tue Oct 29, 2002 2:51 pm
by AVATAr
You have to use sessions.
On each page you check if the session is active, if not you redirect them to the login page.
search the forum.
Posted: Tue Oct 29, 2002 2:58 pm
by m3mn0n
Accually you don't.
I have done many login scripts without sessions, from text files, databases, and with cookies.
In your case, if you do not wish to use sessions or cookies, or text files are too confusing with all there fopen junk ...

... i suggest you do it from a database....
Code: Select all
<?
if ($submit) {
$db=mysql_connect("localhost","username") or die ("cant connect");
mysql_select_db("databasename",$db) or die ("cant change");
$result=mysql_query("select * from members where login='$login'",$db) or die ("Login <b>NOT</b> Successful!");
while ($row=mysql_fetch_array($result)) {
if ($rowї"password"]==$password) {
printf("Welcome, Successfully Logged In!<br><a href="loginpagelink.php"'>Click Here</a>");
}
}
}
?>
You need a form that has the basic username/password feilds, make sure they are named correctly, and don't use GET method, use POST.
The DB tables would be just, id, username, password.
If you want to use more, go wild!~

Posted: Tue Oct 29, 2002 3:44 pm
by austin0369
Now, they wont be able to go thereloginpage.php without having to log in right? also were u say SELECT * whatever do i leave that there or do i edit it and with what?
Posted: Tue Oct 29, 2002 4:34 pm
by austin0369
I cant get it to work...
Posted: Tue Oct 29, 2002 5:51 pm
by volka
The link
PHP Tutorials at the top of this page takes you to some tutorials. One of them is
Creating a Login Script with PHP and MySQL 
Posted: Wed Oct 30, 2002 4:23 pm
by infolock
Here's what you need to do...
Your Script says :
Code: Select all
<?
if($username == test && $password == test1);
{
echo("(HTML CODES GO HERE FOR THERE CERTAIN WESBITE. IN OTHER WORDS I PUT THE HTML INSIDE THE SCRIPT. PROVLEM WITH THIS IS IN THE FUTURE IT WILL BE TO BIG AND HARD TO EDIT)Welcome test!");
}
if($username == test2 && $password == test3);
{
echo("Welcome test2!")
}
?>
This is wrong, as the new version of php has a new style that comes with it. Instead of just calling the variable name from the post box ( in this case, $username ), you have to actually call the POST name itself. This is hard to explain, but here is basically what you need to do different ( i originally had the exact same issue

)
Here is the fix :
NOTE: I can't remember if the name of the actual value has to be in "'s or not, so if this doesn't work , try removin g the ""'s from test, test2, and test3...
Code: Select all
if ((_POSTї'username'] == "test") && (_POSTї'password'] == "test")) {
{
echo("(HTML CODES GO HERE FOR THERE CERTAIN WESBITE. IN OTHER WORDS I PUT THE HTML INSIDE THE SCRIPT. PROVLEM WITH THIS IS IN THE FUTURE IT WILL BE TO BIG AND HARD TO EDIT)Welcome test!");
}
if ((_POSTї'username'] == "test2") && (_POSTї'password'] == "test3"))
{
echo("Welcome test2!")
}
?>
Now, This is defeinately not the way to do this if you are actually wanting to use a login script on your page securely. The best way to do a login authentication script, it to load/retrieve this from a MySQL database.
Here is a script that I made, wiht redirection ( as you are wanting to use ) already in it. So, I would suggest reading this and going that route. Have fun man.
Oops, here is the link :
viewtopic.php?t=3649&highlight=[/b]