Friday, 31 August 2018

PHP code does not work on Ubuntu server

I've written some code in PHP to insert some information into my database. Funny thing is that the code does work on my Windows PC on XAMPP (PHP 5.5.19) but on the Ubuntu Server (lamp-server, PHP 5.5.9) I get a blank page when running it. I don't think it has to do with the permisions because (after a while) i've just set it to CHMOD 777 out of desperate. I've googled for a few hour's (maybe on the wrong term, I have no clue why it doesn't work) but I can't seem to find an answer.

<?php
//includes
include 'connect.php';
include 'salt.php';

if(isset($_POST['registerusername']) && isset($_POST['registerpassword']) && isset($_POST['registeremail'])){
    //escape strings

    $username = mysqli_real_escape_string($con, $_POST['registerusername']);
    $password = mysqli_real_escape_string($con, $_POST['registerpassword']);
    $email = mysqli_real_escape_string($con, $_POST['registeremail']);

    //check mail
    $query = mysqli_query($con, "SELECT email FROM users WHERE email = '$email'")or die(mysqli_error($con));
    if(mysqli_num_rows($query) == 0){
        $num = 1;
        //generate random number
        while($num){
            $id = mt_rand(1000000000, 9999999999);
            $query = mysqli_query($con, "SELECT ID FROM users WHERE ID = '$id'")or die(mysqli_error($con));
            $num = mysqli_num_rows($query);
            echo $num;
        }
        //hash and salt password
        $password = salt($username, $password, $email, date("YmD HiS"));

        //insert in database
        mysqli_query($con, "INSERT INTO users(username, password, registrationdate, email, active, ID) VALUES('$username', '$password',NOW(), '$email', '1', '$id')") or die(mysqli_error($con));

    }
    else{
        //Mail already exist in database
        header("Location: login.php?emailfail");
        die('Nomail');
    }

}
else{
    //fail or nothing inserted in form
    header("Location: login.php?fail");
}
?>


I just want to know what the file include contains. If it does contains
<? instead of <?php

it could be a problem, with the
There could be your problem. I'm not 100% sure, but it did work for me. For a more specific error, instead of a white page, check ini_set ; Regards;

0 comments:

Post a Comment