Page 1 of 2
Code works locally but not when uploaded
Posted: Fri Jan 09, 2015 4:03 pm
by angiestokes
I have been testing some pages locally and they are working fine. I have uploaded the pages to my testing place online and then I try to login I just get a blank screen. (this page is not normally seen by the user as it is processed and then redirected to a landing page.
I am using ApacheFriends XAMPP Version 5.6.3 as my local server/client environment and the mysql is Server version: 5.6.21 - MySQL Community Server. Has anyone got any ideas what could be stopping this working?
Thank you in anticipation..
Angie
Re: Code works locally but not when uploaded
Posted: Fri Jan 09, 2015 4:17 pm
by requinix
Could be any number of reasons.
Checked your error logs yet?
Re: Code works locally but not when uploaded
Posted: Fri Jan 09, 2015 7:47 pm
by Celauran
I'd also make sure display errors and error reporting are turned on until you get this sorted out.
Re: Code works locally but not when uploaded
Posted: Sat Jan 10, 2015 8:55 am
by angiestokes
Thanks I will check the logs and check error messages set.
Re: Code works locally but not when uploaded
Posted: Sat Jan 10, 2015 9:00 am
by angiestokes
I have checked the server error logs and there s nothing in there. I have code in the script that shows me where mt error is
Re: Code works locally but not when uploaded
Posted: Sat Jan 10, 2015 9:05 am
by Celauran
Have you tried posting a simple phpinfo() to confirm PHP is running correctly? If that's working and your script still isn't, you'll need to post some code and tell us what you can about the environment hosting it.
Re: Code works locally but not when uploaded
Posted: Sat Jan 10, 2015 9:24 am
by angiestokes
The phpinfo() worked PHP Version 5.4.21
Here is the code for logging in..
Code: Select all
<?php
session_start(); // needs to be the first thing in the script
//create short variable names
$today = date("j, n, Y");
$timestamp = time();
$time = strftime("%X", $timestamp);
$username = $_REQUEST['requiredUsername'];
$password = $_REQUEST['requiredPassword'];
$password = mhash(MHASH_MD4,$password);
if ($username != "" && $password != ""){ // check for blank fields
// they have just tried logging in
$isuser = login($username, $password); // use the login() function to check the credentials
if ($isuser){ // true therefore they are in the database so register the user id
$_SESSION['valid_user'] = $username; // set a session variable we can test for in other scripts
$message = $_SESSION['userID']." ".$username;
header("Location: members.php?message=".$message); // redirect to a different page than the login page
}else{
// unsuccessful login
$message = 'You could not be logged in.';
// $message =$username." ".$password;
header("Location: index.php?message=".$message);
}//end if 1
}else{ // missing username or password
$message = 'You must enter a username and password.';
header("Location: index.php?message=".$message);
}// end if 2
function login($username, $password){
// check username and password with db
// if yes, return true
// else return false
include_once 'dbConnect.php';
// Connect to server and select databse.
$linkID = mysql_connect(HOST, USER, PASSWORD);
mysql_select_db(DATABASE, $linkID);
//set error reporting to display and to it's highest level in case
$resultID = mysql_query("SELECT * FROM user where username = '$username' AND password = '$password'", $linkID)or die(mysql_error());
if (mysql_num_rows($resultID)>0){ //there was a result so the user is valid
$_SESSION[usertype] = 'valid_user'; // set a session variable we can use elsewhere
while($row=mysql_fetch_array($resultID)){
$_SESSION[userID] = $row['userID'];
$userID = $row['userID'];
$_SESSION[adminstatus] = $row['adminstatus'];
$_SESSION[name] = $row['name'];
$result = mysql_query("INSERT INTO logon(userID, date) VALUES ('$userID', Now())", $linkID) or die(mysql_error());
}// while
return true;
}else{
return false;
}// end if
}// end function
?>
Re: Code works locally but not when uploaded
Posted: Sat Jan 10, 2015 9:30 am
by Celauran
Have you been able to ascertain where it's failing? I see some undefined constants in there, and no includes to suggest where they may be defined. What sort of errors are being displayed?
Re: Code works locally but not when uploaded
Posted: Sat Jan 10, 2015 9:32 am
by angiestokes
No I am just getting a blank page. it all works on my local machine
Re: Code works locally but not when uploaded
Posted: Sat Jan 10, 2015 9:37 am
by Celauran
Turn on error reporting.
Code: Select all
<?php
ini_set('display_errors', '1');
error_reporting(-1);
Re: Code works locally but not when uploaded
Posted: Sat Jan 10, 2015 9:47 am
by angiestokes
ok I did that it is telling me
Fatal error: Call to undefined function mhash() in /home/astokes4/public_html/timebank/loginpage.php on line 12
This is working on the local machine what do i have to do to allow it to work online. Anyideas?
Re: Code works locally but not when uploaded
Posted: Sat Jan 10, 2015 9:56 am
by Celauran
Not sure how much control you'd have over that on shared hosting. You could use
hash() instead.
Re: Code works locally but not when uploaded
Posted: Sat Jan 10, 2015 9:57 am
by Celauran
As a side note, if this is a new application, you really don't want to be using the outdated md4 hashing algorithm. If it's a legacy project that you're maintaining, that's another story, but still something you may want to consider updating.
Re: Code works locally but not when uploaded
Posted: Sat Jan 10, 2015 10:03 am
by angiestokes
OK thanks I was suggested to use this to encrypt the password. Previous to this I have just stored the password as normal. Is there something else I could use to encrypt the password instead.
Re: Code works locally but not when uploaded
Posted: Sat Jan 10, 2015 10:05 am
by Celauran
Use bcrypt. Also, take a look at PHP's
password hashing FAQ.