Hi folks,
I created a login form for accessing a protected page on my site. This works fine on my test server (WAMP 3.2) running MySql and PHP 7. When I transfer the files (connection script and login page) to my hosting server nothing seems to happen when I submit the form. I don’t even know where to begin troubleshooting it as I am not getting any errors, just nothing.
I am not sure where the difference between my test server and hosting server is. I am running the same PHP version and MySQL on both; I made sure that I changed the HOST and PORT on my connection script before uploading to the web host and the database was imported to my test server from the web host and has the same database user credentials and privileges.
What's more, the original scripts were in PHP 5 (with mysql commands as opposed to mysqli). I can switch back to the old scripts and regress the PHP version on the hosting server and everything works. Clearly I don't want to leave it this way because of the deprecated code.
I don't expect anyone to do the work for me but even if someone can offer some tips on troubleshooting as nothing that I can see is happening when I submit on my host and, as I said, the script works flawlessly on my test server. Of course if someone did spot the a flaw in my code...
Here is my script in case anyone sees something I missed.
CONNECTION SCRIPT:
LOGIN FORM SCRIPT:
Thanks in advance for any help.
Ken
I created a login form for accessing a protected page on my site. This works fine on my test server (WAMP 3.2) running MySql and PHP 7. When I transfer the files (connection script and login page) to my hosting server nothing seems to happen when I submit the form. I don’t even know where to begin troubleshooting it as I am not getting any errors, just nothing.
I am not sure where the difference between my test server and hosting server is. I am running the same PHP version and MySQL on both; I made sure that I changed the HOST and PORT on my connection script before uploading to the web host and the database was imported to my test server from the web host and has the same database user credentials and privileges.
What's more, the original scripts were in PHP 5 (with mysql commands as opposed to mysqli). I can switch back to the old scripts and regress the PHP version on the hosting server and everything works. Clearly I don't want to leave it this way because of the deprecated code.
I don't expect anyone to do the work for me but even if someone can offer some tips on troubleshooting as nothing that I can see is happening when I submit on my host and, as I said, the script works flawlessly on my test server. Of course if someone did spot the a flaw in my code...
Here is my script in case anyone sees something I missed.
CONNECTION SCRIPT:
PHP:
<?php
$hostname_conn_lcp = "my.dreamhost.sql.hostname";
$username_conn_lcp = "username";
$password_conn_lcp = "password";
$database_conn_lcp = "db_name";
$port_conn_lcp = "3306";
$conn_lcp = mysqli_connect($hostname_conn_lcp, $username_conn_lcp, $password_conn_lcp, $database_conn_lcp, $port_conn_lcp);
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
?>
LOGIN FORM SCRIPT:
PHP:
<?php require_once('Connections/conn_lcp.php'); ?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['userName'])) {
$loginUsername=$_POST['userName'];
$password=md5($_POST['password']);
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "path-to/protected-page.php";
$MM_redirectLoginFailed = "portal-login.php?status=loginfailure";
$MM_redirecttoReferrer = false;
mysqli_select_db($conn_lcp, $database_conn_lcp);
$LoginRS__query=sprintf("SELECT UserName, password FROM tblusers WHERE UserName='$loginUsername' AND password='$password'");
$LoginRS = mysqli_query($conn_lcp, $LoginRS__query) or die(mysqli_error($conn_lcp));
$loginFoundUser = mysqli_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
Thanks in advance for any help.
Ken