Chris Z is right on the connection script. You should leave the db server at local host:
PHP Code:
<?php
$database['dbserver'] = 'localhost';
$database['dbuser'] = 'cascades_sope1';
$database['dbname'] = 'cascades_sope1';
$database['dbpass'] = 'Removed For Obvious Reasons';
$table = 'users';
$connect = mysql_connect($database['dbserver'], $database['dbuser'], $database['dbpass']);
$select= mysql_select_db($database['dbname']);
?>
As for your login script, I use the following:
PHP Code:
<?php
session_start();
// Require once the DB script
require_once ($_SERVER['DOCUMENT_ROOT']. '/config.php');
if ($_POST['loginSubmit']) {
// You *always!* need to validate user-supplied data when using it in MySQL queries!!
// This isn't 100% secure, but it's definitely better than having nothing and being vulnerable to SQL injection.
if(get_magic_quotes_gpc()) {
if(ini_get('magic_quotes_sybase')) {
$username = str_replace("''", "'", $_POST['username']);
$password = str_replace("''", "'", $_POST['password']);
} else {
$username = stripslashes($_POST['username']);
$password = stripslashes($_POST['password']);
}
} else {
$username = $_POST['username'];
$password = $_POST['password'];
}
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$check = mysql_query("SELECT * FROM `users` WHERE `users` = '$username' and `password` = '$password' LIMIT 1");
// Counting the table row
// If the result is matched then $username, $password must be row 1
$count = @mysql_num_rows($check);
// Logged in!
if ($count == (int) 1) {
$_SESSION['site_username'] = $username;
$_SESSION['site_password'] = $password;
echo '<link rel="stylesheet" href="style.css" type="text/css" />
<div align="center">Welcome '. $_SESSION['site_username'] .'. You are now logged in!<br /><a href="members">Click Here to Continue</a></div>';
$_GET['do'] = 'manualUnset';
// Do whatever ?
}
else {
echo 'Error: Wrong username or password specified. <br />';
}
}
// If $_GET['do'] is set to 'manualUnset', do not show login form, user already logged in.
switch ($_GET['do']) {
case 'manualUnset':
break;
default:
?>
<link rel="stylesheet" href="style.css" type="text/css" />
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="90%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td>Username:</td>
<td>Password:</td>
</tr>
<tr>
<td><input type="text" name="username" /></td>
<td><input type="password" name="password" /> <input name="loginSubmit" type="submit" value="Login" class="button" /></td>
</tr>
</table>
</form>
<?php
break;
}
?>
If you have any more problems please let us know. Obviously the script I use is tailored to my needs, and if you want to use it you are more than welcome. All you would have to do is change around the names used in the script.
Regards,
Zenax