Script works fine on test server but not on production server

Joined
Jul 23, 2020
Messages
4
Reaction score
1
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:
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
 
Joined
Jul 12, 2020
Messages
89
Reaction score
9
Run the form by itself, without db connect and see what happens. That should show you where to start.
 
Joined
Nov 27, 2019
Messages
163
Reaction score
28
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
} <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Don't think this should be here!
header("Location: " . $MM_redirectLoginSuccess);
} else {
header("Location: " . $MM_redirectLoginFailed);
}
 
Joined
Jul 23, 2020
Messages
4
Reaction score
1
Hey folks,

Sorry for not replying to the thread in so long. I got it sussed. Turns out there was white space at the end of my login script. It didn't make any difference on my test environment but in the production server it produced errors. The hosting service suppresses errors so I was able to show them by adding:

PHP:
ini_set('display_errors',1);
error_reporting(E_ALL);

to the top of my script. Once I saw the errors, a quick Google and all good.

Thanks for all your help.

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top