Niels
May 11 2002, 07:43 PM
Can someone please give me a login system in PHP.
I have connected to the server and defined $database to the database.
Now i have no idea what to do.
Please help me!
I will send 3$ into your paypal if you can help me!
3a3
May 11 2002, 08:20 PM
that depends on what login system do you want to use ..
You can use really lame and unsecure login system, and you can use SSL protocol to login ..
one of the best places to search for is:
http://www.hotscripts.com/PHP/Scripts_and_...Authentication/if you wanna pay me .. then my e-gold acct # is 370024 .. I don't have paypal ..
thasith
May 11 2002, 08:25 PM
don't pay 3a3 even a single cent!
He's rich and know too much php LOL!
Niels, what site are you trying to make?
3a3
May 11 2002, 08:43 PM
quote:
Originally posted by thasith:
don't pay 3a3 even a single cent!
He's rich and know too much php LOL!
Niels, what site are you trying to make?
thanks, Thasith .. I would have shared with you some money .. but I guess you don't need it .. LOL!!!!
Niels
May 11 2002, 09:04 PM
First it will be paid email. Then it will be paid to visit too. There is also a news site and some otehr stuff.
Niels
May 11 2002, 09:05 PM
And about paying on Egold that is a problem as i dont have one cent there.
3a3
May 11 2002, 09:30 PM
I don't care actually .. ..
Niels
May 11 2002, 09:49 PM
Those scripts dont allow for any editing which means i cant even get them to connect to my database. Isnt there anyone that can give me a ready one?
Yrlec
May 12 2002, 02:17 AM
Here's a script for ya...
It actually is two scripts, one that handles the login (login.php) and one that is included one every page that only users that have logged in should be able to access (verify.inc.php). Since
I don't have MySql on my computer (I assumed that you were running MySql) I haven't been able to test them yet, so please use them with care...
Here's login.php's code :
//check if a username and a password is defined
if(!$username || !$password)
{
echo 'No username/password';
exit;
}
else
{
//include the file with the database username and password
include("C:mysql_connect.inc");
//connect to the database
mysql_connect($mysql_host,$mysql_username,$mysql_password) or die("MySQL Error: " . mysql_errno() . ": " . mysql_error());
//encrpyt the password, for security reasons
$password = md5($password);
//select the correct database
mysql_select_db('database');
//query the database to see if the username and password is correct
$result = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'") or die("MySQL Error: " . mysql_errno() . ": " . mysql_error());
if(mysql_num_rows($result)!=1)
{
//it's invalid
echo 'Invalid username/password';
exit;
}
else
{
//it's valid so redirect the user to the secret page and save the username and the password in two cookies
setcookie("userlogin",$username,'',"/");
setcookie("passlogin",$password,'',"/");
header("Location: secretpage.php");
}
}
Here's verify.inc.php's code:
if (!$userlogin || !$passlogin)
{
//the user is not logged in so send him to the login-page
header('Location: loginform.html');
exit;
}
//include the file with the database username and password
include("C:mysql_connect.inc");
//connect to the database
mysql_connect($mysql_host,$mysql_username,$mysql_password) or die("MySQL Error: " . mysql_errno() . ": " . mysql_error());
//select the correct database
mysql_select_db('database');
//query the database to see if the username and password is correct
$result = mysql_query("SELECT * FROM users WHERE username='$userlogin' AND password='$passlogin'") or die("MySQL Error: " . mysql_errno() . ": " . mysql_error());
if (mysql_num_rows($result)!=1)
{
//the username/password is invalid so send the user to the login page
header('Location:loginform.html');
exit;
}
They're quiet well-commented so you should be able to understand how they work, otherwise consuly PHP's wonderful manual.
Niels
May 12 2002, 04:26 AM
Many thanks i'm so glad that you can help.
YBonline
May 13 2002, 04:48 AM
While Yrlec's script should work fine, You may want to actually include the file rather then use header("Location: page.php"); for two reasons:
1) Easier to customize the page
2) It keeps the secret page actually a secret, so that person can't tell others about that page as easily
His script will work just fine though. It has very good encryption as well, same that will be used by (parts) of GPS:
$password = md5($password);
Yrlec
May 13 2002, 06:08 AM
quote:
Originally posted by YBonline:
While Yrlec's script should work fine, You may want to actually include the file rather then use header("Location: page.php"); for two reasons:
1) Easier to customize the page
2) It keeps the secret page actually a secret, so that person can't tell others about that page as easily
His script will work just fine though. It has very good encryption as well, same that will be used by (parts) of GPS:
$password = md5($password);
I agree with you on most of your points but I don't understand how it would be more customizable when using include instead of location. If you want to password-protect several pages it's definetely easier to just redirect the user and then include a script on every page you want to protect that checks if the user is actually logged in.
Well, there's always different ways to do things and they all have their pros and cons so I guess it's very hard to tell which script would be best, it completely depends on the situation.
I actually think GPS is quiet similiar to Degoo's code, I also use PHP and SQL and I also store the upline not the downline, which saves a lot of resources. I think the largest difference is that I use PostgreSQL instead of MySQL, but I acutally wrote it for MySQL at first, but I ported it about a year ago.
YBonline
May 13 2002, 12:58 PM
quote:
Originally posted by Yrlec:
I actually think GPS is quiet similiar to Degoo's code, I also use PHP and SQL and I also store the upline not the downline, which saves a lot of resources. I think the largest difference is that I use PostgreSQL instead of MySQL, but I acutally wrote it for MySQL at first, but I ported it about a year ago.
Do you mind if I ask why you did it? Whats the advantage of pgSQL? I never used it really so I don't know... Also it would be very easy to port GPS to other databases by simpily replacing one file in the entire program. All SQL connections are done in one file for the reason of switching to other database drivers if you ever want to.
Yrlec
May 13 2002, 02:52 PM
It was after reading a lot of articles on the Internet that I felt that Postgresql would fit my project better. Three great MySQL and PostgreSQL comparisons are these:
http://www.mmlabx.ua.es/mysql-postgres.html http://www.phpbuilder.com/columns/tim20001112.php3 http://openacs.org/philosophy/why-not-mysql.html [ 05-14-2002, 04:54 AM: Message edited by: Yrlec ]
3a3
May 16 2002, 01:13 AM
well .. I talked to some other guys and they told me this:
there's no difference whether you write '".$val1."' or '$val1', because that's exactly the same, you just insert the $val1 variable in different ways.
If you want your query to be safe against hack attempts, then you should use addslashes() function.
.. after reading, what does addslashes function, I understood, that they are completely right, there's no difference between writing the ways above .. it's still vulnerable ..
Yrlec
May 16 2002, 02:26 AM
quote:
Originally posted by 3a3:
well .. I talked to some other guys and they told me this:
there's no difference whether you write '".$val1."' or '$val1', because that's exactly the same, you just insert the $val1 variable in different ways.
If you want your query to be safe against hack attempts, then you should use addslashes() function.
.. after reading, what does addslashes function, I understood, that they are completely right, there's no difference between writing the ways above .. it's still vulnerable ..
Yeah, that's correct but I wasn't talking about that. I was talking about queries that don't have any single-quotes. Your example above does have single-quotes in. PHP, by default, runs all GPC-data through addslashes so you shouldn't have to worry about that.
3a3
May 16 2002, 06:47 PM
I guess you're right .. we're talking about two different things ..
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.