Basic Login Script with PHP A rudimentary login script tutorial aimed at those looking to learn ho
#16
Posted 09 October 2008 - 08:48 AM
thanks and thank you very very much....!!!!
#17
Posted 12 October 2008 - 12:02 AM
Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\conn.php on line 9
#18
Posted 12 October 2008 - 01:08 PM
fallenOne09, on 12 Oct, 2008 - 03:02 AM, said:
Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\conn.php on line 9
You're probably missing a semicolon at the end of one of your lines. Check line 8. Post any additional questions in the forum so we can keep this thread open just for questions about the tutorial. Thanks.
#19
Posted 18 February 2009 - 04:10 PM
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Thanks for the tut!
I know that in my 1&1 account, it mentions this:
Important MySQL Usage Information
The MySQL database may not be used for log evaluation operations, ad clicks, chat systems, banner rotations, or similar applications putting extreme loads on the database under any circumstances.
Your MySQL databases are stored behind a firewall to protect your data. You can only access each one exclusively through your server. Direct access to your MySQL databases using a home PC (external ODBC connection) cannot be established.
Could that have something to do with this error?
This post has been edited by myjunkb0x: 18 February 2009 - 04:24 PM
#20
Posted 19 February 2009 - 10:50 AM
I googled the error real quick, and it appears to be due to a configuration error. You may need to have 1&1 check the configuration.
Hope that helps.
#21
Posted 19 February 2009 - 10:54 AM
akozlik, on 19 Feb, 2009 - 09:50 AM, said:
I googled the error real quick, and it appears to be due to a configuration error. You may need to have 1&1 check the configuration.
Hope that helps.
I did contact 1&1 and they said that support for MySQL is beyond their support.
I also Googled the error too and found that it could be a server error of some kind such as resetting permissions, etc.
So I thought, I'll call 1&1 and ask them to help me with the phpmyadmin that they have provided me with. They said that it MUST be a script error on my behalf.
I'm so tired of this s--- (with PHP, login, code, etc.)
All I want to do is provide a login for my customers so that they can view their photos (I'm a photographer) on my website.
Thanks for your reply!
#22
Posted 19 February 2009 - 11:04 AM
Quote
Thanks for your reply!
Yeah, it's difficult to help you out without having direct access to everything. I have a feeling 1&1 may be giving you the run around, but I'd have to take a look for sure. For them to say that they don't handle MySQL is ridiculous. They provide web hosting so they have access to the servers.
If you're tired of playing around with it yourself, I'm a freelance programmer who has a slot open for some work. If you're interested, you can contact me on AIM at duke00785 or e-mail at akozlik ( a t ) gmail.com
Hope to hear from you.
Andrew
#23
Posted 23 February 2009 - 11:40 AM
#24
Posted 25 February 2009 - 08:37 AM
<?php $username = 'your_username'; $password = 'your_password'; $host = 'your_host'; $db = 'your_database'; $conn = mysql_connect($host, $username, $password); $db = mysql_select_db($db, $conn); ?>
#25
Posted 25 February 2009 - 08:59 AM
myjunkb0x, on 18 Feb, 2009 - 05:10 PM, said:
FYI, 1&1 holds ALL their MySQL databases through a virtual connection environment. Therefore only those connections from within 1&1 servers will be able to attach to them via connection strings. I have spent months trying to get them to open the firewall for my databases but they wont. 1&1 is a great point to start learning web dev but i would suggest moving out of it when you get a chance and feel confortable flying out into the world on your own.
#26
Posted 03 March 2009 - 02:33 AM
<form action="file:///C|/Users/shaun/Downloads/checkLogin.php" method="post">
<table>
<tr>
<td>Username: </td>
</td><input type="text" name="user"></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password"></td>
<input type="submit" value="Submit">
</tr>
</table>
</form>
<?php
// checkLogin.php
$username = "root";
$password = "";
$host = "localhost";
$database = "users";
$conn = mysql_connect($host, $username, $password) or die ( "Could not connect: " . mysql_error() );
$database = mysql_select_db($database, $conn) or die ("Could not select database: " . mysql_error() );
session_start(); // Start a new session
require('file:///C|/Users/shaun/Downloads/conn.php'); // Holds all of our database connection information
// Get the data passed from the form
$username = $_POST['user'];
$password = $_POST['password'];
// Do some basic sanitizing
$username = stripslashes($username);
$password = stripslashes($password);
$sql = "select * from users where username = '$username' and password = '$password'";
$result = mysql_query($sql) or die ( mysql_error() );
$count = 0;
while ($line = mysql_fetch_assoc($result)) {
$count++;
}
if ($count == 1) {
$_SESSION['loggedIn'] = "true";
header("Location: loginSuccess.php"); // This is wherever you want to redirect the user to
} else {
$_SESSION['loggedIn'] = "false";
header("Location: loginFailed.php"); // Wherever you want the user to go when they fail the login
}
?>
Please help me with this code.
What more can I do to get it to work properly?
<form action="file:///C|/Users/shaun/Downloads/checkLogin.php" method="post">
<table>
<tr>
<td>Username: </td>
</td><input type="text" name="user"></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password"></td>
<input type="submit" value="Submit">
</tr>
</table>
</form>
<?php
// checkLogin.php
$username = "root";
$password = "";
$host = "localhost";
$database = "users";
$conn = mysql_connect($host, $username, $password) or die ( "Could not connect: " . mysql_error() );
$database = mysql_select_db($database, $conn) or die ("Could not select database: " . mysql_error() );
session_start(); // Start a new session
require('file:///C|/Users/shaun/Downloads/conn.php'); // Holds all of our database connection information
// Get the data passed from the form
$username = $_POST['user'];
$password = $_POST['password'];
// Do some basic sanitizing
$username = stripslashes($username);
$password = stripslashes($password);
$sql = "select * from users where username = '$username' and password = '$password'";
$result = mysql_query($sql) or die ( mysql_error() );
$count = 0;
while ($line = mysql_fetch_assoc($result)) {
$count++;
}
if ($count == 1) {
$_SESSION['loggedIn'] = "true";
header("Location: loginSuccess.php"); // This is wherever you want to redirect the user to
} else {
$_SESSION['loggedIn'] = "false";
header("Location: loginFailed.php"); // Wherever you want the user to go when they fail the login
}
?>
#27
Posted 03 March 2009 - 11:28 AM
#28
Posted 01 May 2009 - 10:10 AM
ConnVars.inc - is the connection variables for the LOGIN.PHP
<?php $auth_host = "localhost"; $auth_user = "str_auth"; // what ever ID you want to use $auth_pass = ""; $auth_dbase = "strikers"; // what ever DB you want to connect to with the above info ?>
The above $auth_user would be an account created specifically for use from the web. It should have ONLY select access, and your server should be setup not to allow access to the INC file type. That's my opinion.
LOGIN.PHP - actually processes my login.
<?php
include "ConnVars.inc";
$USERID = $_POST['CHARID'];
$USERPW = $_POST['CHARPW'];
$LookupCon = mysql_connect($auth_host,$auth_user,$auth_pass);
$Lookupdb = mysql_select_db($auth_dbase,$LookupCon);
$query = "SELECT * FROM account WHERE username='$USERID';";
$LINKLIST = mysql_query($query) or die(mysql_error());
$COUNTER = mysql_num_rows($LINKLIST);
$LINKDATA = mysql_fetch_row($LINKLIST);
if($COUNTER == 1)
{
if($LINKDATA[1] == $USERPW)
{
$response = "step01.html";
}
else
{
$response = "failed2.html";
}
}
else
{
$response = "failed1.html";
}
header("Location: ".$response);
mysql_close($LookupCon);
?>
I have setup other logins (just not this one) to catch whether I have MORE than one identical user name in the DB, by using the "$COUNTER = mysql_num_rows($LINKLIST);".
Which means "I" screwed up and didn't verify the account name during the creation process.
#29
Posted 27 July 2009 - 02:26 AM
This post has been edited by paperclipmuffin: 27 July 2009 - 02:36 AM
#30
Posted 25 September 2009 - 12:28 PM
You'll definitely need to md5() the password to encrypt it. Otherwise, the login isn't secure.
|
|








MultiQuote






|