Code works locally but not when uploaded

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

angiestokes
Forum Newbie
Posts: 9
Joined: Fri Jan 09, 2015 3:55 pm

Code works locally but not when uploaded

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Code works locally but not when uploaded

Post by requinix »

Could be any number of reasons.

Checked your error logs yet?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Code works locally but not when uploaded

Post by Celauran »

I'd also make sure display errors and error reporting are turned on until you get this sorted out.
angiestokes
Forum Newbie
Posts: 9
Joined: Fri Jan 09, 2015 3:55 pm

Re: Code works locally but not when uploaded

Post by angiestokes »

Thanks I will check the logs and check error messages set.
angiestokes
Forum Newbie
Posts: 9
Joined: Fri Jan 09, 2015 3:55 pm

Re: Code works locally but not when uploaded

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Code works locally but not when uploaded

Post 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.
angiestokes
Forum Newbie
Posts: 9
Joined: Fri Jan 09, 2015 3:55 pm

Re: Code works locally but not when uploaded

Post 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

?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Code works locally but not when uploaded

Post 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?
angiestokes
Forum Newbie
Posts: 9
Joined: Fri Jan 09, 2015 3:55 pm

Re: Code works locally but not when uploaded

Post by angiestokes »

No I am just getting a blank page. it all works on my local machine
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Code works locally but not when uploaded

Post by Celauran »

Turn on error reporting.

Code: Select all

<?php
ini_set('display_errors', '1');
error_reporting(-1);
angiestokes
Forum Newbie
Posts: 9
Joined: Fri Jan 09, 2015 3:55 pm

Re: Code works locally but not when uploaded

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Code works locally but not when uploaded

Post by Celauran »

Not sure how much control you'd have over that on shared hosting. You could use hash() instead.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Code works locally but not when uploaded

Post 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.
angiestokes
Forum Newbie
Posts: 9
Joined: Fri Jan 09, 2015 3:55 pm

Re: Code works locally but not when uploaded

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Code works locally but not when uploaded

Post by Celauran »

Use bcrypt. Also, take a look at PHP's password hashing FAQ.
Post Reply