5

I am creating an e-Commerce site, I had been using Magento previously but am changing to a custom built site instead.

On this site, I had created a page called create_account.php, this was fine for a while and it worked great but then it started throwing a 410 error which I had never seen before. Did a bit of research and could see that this indicates the file did exist but isn't there any more.

enter image description here

I thought fair enough maybe Magento had a file with the same name and it has a record of this file being deleted so it stopped reading my file, so I'll create a copy of it, call it something else and change all references to that file to the new name of account_create.php and put in a line in my .htaccess file to redirect users that may be going to the first one to my new file, but I left the original file on the server.

That worked fine for a while (am talking about days rather than hours/minutes) on multiple computers/browsers/networks etc, but then the same thing happened. This time I thought it couldn't be something left over from Magento or something else that the server still had a record of, but if that fix worked the last time I'll try it and see how it goes.

This has now happened 6 times with 6 different file names for the same file over the space of a month where it is working for a few days and then the server says the file is gone. However, all 6 files are still in the main directory on my server. I have a 7th version with a new name that is currently working but am not holding out hope and my .htaccess file is getting ridiculous.

  RewriteRule ^create_account/?$ create.php [L,NC,QSA]
  RewriteRule ^createaccount/?$ create.php [L,NC,QSA]
  RewriteRule ^accountcreate/?$ create.php [L,NC,QSA]
  RewriteRule ^account_create/?$ create.php [L,NC,QSA]
  RewriteRule ^account_creation/?$ create.php [L,NC,QSA]
  RewriteRule ^accountcreation/?$ create.php [L,NC,QSA]

I'm starting to doubt the actual file itself although everything works fine locally on WAMP and it works fine for a while live before this happens. Here is the contents of this file:

<?php
$active_country_id = $_SESSION["active_country_id"];
$active_country_name = $_SESSION["active_country_name"];
$active_country_code = $_SESSION["active_country_code"];
$active_country_currency = $_SESSION["active_country_currency"];
$active_country_vat = $_SESSION["active_country_vat"];
$active_country_braintree = $_SESSION["active_country_braintree"];

$message = "";
$first_name = "";
$last_name = "";
if(isset($_POST['company_name'])){$company = $_POST['company_name'];}else{$company = "";}
$email = "";
$phone = "";
$password1 = "";
$password2 = "";
$parsed = "";

if(isset($_GET['id']) && $_GET['id'] != ""){
    $id = $_GET['id'];
    $params = [$id];
    $sql = "SELECT * FROM customers WHERE id=?";
    $stmt = DB::run($sql,$params);
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        $first_name = $row["first_name"];
        $last_name = $row["last_name"];
        $email = $row["email"];
    }
}

if (isset($_POST['first_name'])){
    if (isset($_POST['first_name']) && $_POST['first_name']!=""){
        $first_name = $_POST['first_name'];
        $parsed = "true";
    }else{
        $message .= "<div id='warning'>";
        $message .= "First Name is a required field";
        $message .= "</div>";
        $parsed = "false";
    }
    if (isset($_POST['last_name']) && $_POST['last_name']!=""){
        $last_name = $_POST['last_name'];
        $parsed = "true";
    }else{
        $message .= "<div id='warning'>";
        $message .= "Surname is a required field";
        $message .= "</div>";
        $parsed = "false";
    }
    if (isset($_POST['email']) && $_POST['email']!=""){
        $email = $_POST['email'];
        $parsed = "true";
    }else{
        $message .= "<div id='warning'>";
        $message .= "Email is a required field";
        $message .= "</div>";
        $parsed = "false";
    }
    if (isset($_POST['phone']) && $_POST['phone']!=""){
        $phone = $_POST['phone'];
        $parsed = "true";
    }else{
        $message .= "<div id='warning'>";
        $message .= "Phone Number is a required field";
        $message .= "</div>";
        $parsed = "false";
    }
    if (isset($_POST['password1']) && $_POST['password1']!=""){
        $password1 = $_POST['password1'];
        $parsed = "true";
    }else{
        $message .= "<div id='warning'>";
        $message .= "Both password fields are required";
        $message .= "</div>";
        $parsed = "false";
    }
    if (isset($_POST['password2']) || $_POST['password2']!=""){
        $password2 = $_POST['password2'];
        $parsed = "true";
    }else{
        $message .= "<div id='warning'>";
        $message .= "Both password fields are required";
        $message .= "</div>";
        $parsed = "false";
    }
    if ($_POST['password1'] == $_POST['password2']){
        $parsed = "true";
    }else{
        $message .= "<div id='warning'>";
        $message .= "Password fields must match";
        $message .= "</div>";
        $parsed = "false";
    }
    if($parsed == "true")
    {
        $params = [$email];
        $sql = "SELECT * FROM customers WHERE email=?";
        $stmt = DB::run($sql,$params);
        $customerCount = $stmt->rowCount();
        if ($customerCount < 0) {
            $message .= "<div id='warning'>";
            $message .= "A customer with this email address already exists";
            $message .= "</div>";
        }else{
            if(isset($_GET['id']) && $_GET['id'] != ""){
                $customer_id = $_GET['id'];
                $params1 = [$first_name,$last_name,$email,$password1,$company,$phone,$customer_id];
                $sql1 = "UPDATE customers set first_name=?, last_name=?, email=?, password=?, last_log_date=now(), company=?, phone=? WHERE id=?";
                $stmt1 = DB::run($sql1,$params1);
            }else{
                $params2 = [$first_name,$last_name,$email,$password1,$company,$phone];
                var_dump($params2);
                $sql2 = "INSERT INTO customers (first_name, last_name, email, password, last_log_date, company, phone) VALUES(?,?,?,?,now(),?,?)";
                $stmt2 = DB::run($sql2,$params2);
                $customer_id = DB::lastInsertId();
            }
            $to = $email;
            $subject = "Your example.com account";
            $message_header = file_get_contents("mail/email_header.php");
            $message_content = file_get_contents("mail/account_created.php");
            $message_content = str_replace('%first_name%', $first_name, $message_content); 
            $message_content = str_replace('%last_name%', $last_name, $message_content); 
            $message_content = str_replace('%email%', $email, $message_content);
            $message_footer = file_get_contents("mail/email_footer.php");
            $message_to_send = $message_header.$message_content.$message_footer;
            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
            $headers .= "From: support@example.com" . "\r\n";
            $headers .= "Reply-To: support@example.com" . "\r\n";
            mail($to,$subject,$message_to_send,$headers);

            $cookie_string = $customer_id.'%'.$first_name.'%'.$last_name;
            $cipher = 'aes128';
            $key = '*****';
            $iv = '****************';
            $encrypted_cookie_string = openssl_encrypt($cookie_string,$cipher,$key,$options=0,$iv);
            setcookie("example_customer",$encrypted_cookie_string,time()+(60*60*24*30),"/");
            header("location: create");
        }
    }
}
if(isset($_COOKIE["example_customer"])){
    header("location: account");
    exit();
}
?>

<!DOCTYPE html>
<html>
<head>
<?php include_once("analytics.php"); ?>
<?php include_once("base.php"); ?>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="web/style.css" type="text/css" media="screen"/>
<link rel="shortcut icon" type="image/ico" href="web/favicon.ico"/>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="web/script.js"></script>
<title>
</title>
</head>
<body>
<div id="mainWrapper">

    <div id="pageHeader">
        <?php include_once("page_header.php"); ?>
    </div>

    <div id="pageContent">
        <!--<div id="sidebar">
            <?php include_once("page_sidebar.php"); ?>
        </div>-->
        <div id="mainContent">
            <center>
            <?php echo $message ?>
            <form id="create_account_form" name="create_account_form" method="post" action="create">
            <center><img src="web/example_logo_bg.png"></center>
            <h2>Create Account</h2>
            First Name:
            <br />
            <input name="first_name" type="text" id="first_name" size="40" placeholder="First Name">
            <br /><br />            
            Surname:
            <br />
            <input name="last_name" type="text" id="last_name" size="40" placeholder="Last Name"/>
            <br /><br />            
            Company Name:
            <br />
            <input name="company_name" type="text" id="company_name" size="40" placeholder="Company Name"/>
            <br /><br />
            Email:
            <br />
            <input name="email" type="text" id="email" size="40" placeholder="Email"/>
            <br /><br />
            Phone Number:
            <br />
            <input name="phone" type="text" id="phone" size="40" placeholder="Phone Number"/>
            <br /><br />
            Password:
            <br />
            <input name="password1" type="password" id="password1" size="40" placeholder="Password"/>
            <br /><br />
            Confirm Password:
            <br />
            <input name="password2" type="password" id="password2" size="40" placeholder="Password"/>
            <br /><br />
            <center>
            <button name="create_account" id="create_account" onclick=this.form.submit();>Create Account</button>
            </center>
            </form>
        </center>
        </div>
    </div>

</div>
</body>
</html>

I am seeking a bit more understanding into the 410 error itself or what could cause this.

Edit

My full .htaccess file:

Options -MultiViews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^category/([0-9a-zA-Z-]+)/?$ category.php?id=$1 [L,NC,QSA]
RewriteRule ^product/([0-9a-zA-Z-]+)/?$ product.php?id=$1 [L,NC,QSA]
RewriteRule ^product/([0-9a-zA-Z-]+)/added?$ product.php?id=$1&added=added [L,NC,QSA]
RewriteRule ^page/([0-9a-zA-Z-]+)/?$ page.php?page_id=$1 [L,NC,QSA]
RewriteRule ^order/([0-9a-zA-Z-]+)/?$ order.php?id=$1 [L,NC,QSA]

RewriteRule ^create_account/?$ creation.php [L,NC,QSA]
RewriteRule ^createaccount/?$ creation.php [L,NC,QSA]
RewriteRule ^accountcreate/?$ creation.php [L,NC,QSA]
RewriteRule ^account_create/?$ creation.php [L,NC,QSA]
RewriteRule ^account_creation/?$ creation.php [L,NC,QSA]
RewriteRule ^accountcreation/?$ creation.php [L,NC,QSA]
RewriteRule ^create/?$ creation.php [L,NC,QSA]

RewriteRule ^([^\.]+)$ $1.php [L,NC,QSA]

enter image description here

If possible I would like to confirm that the php file is ok or at least if there was an issue with it, that it would throw a usual php error rather than a http response saying the file doesn't exist any more.

halfer
  • 19,824
  • 17
  • 99
  • 186
Paddy Hallihan
  • 1,624
  • 3
  • 27
  • 76
  • This just happened again. It was working for 2-3days this time. No idea what could be causing this – Paddy Hallihan Apr 23 '18 at 08:16
  • Do you have any `RewriteRule ^(.*)$ http://airbrake.io/expired_page$1 [R=410,L]` rules, that have `r=410`? check .htaccess and your apache configuration. Also, check your command logs if you're running on unix. also read your apache logs. – Tschallacka Apr 23 '18 at 08:25
  • @Tschallacka I have added my full .htaccess above and am struggling to try find the apache logs on my shared server (hosted by register365). I do not think there is an issue with the actual php file? – Paddy Hallihan Apr 23 '18 at 08:36
  • If you are rewriting `^accountcreation/?$`, then why does it say `.../accountcreation.php` in your screenshot? – CBroe Apr 23 '18 at 08:40
  • Consider shilling out a few extra euros and buy a dedicated server you control. at strato for example you get a linux vps for 9 euros a month.Then you control everything, every setting you need, and you can host multiple domains on the same site, etc... Just a suggestion. As for your redirects, consider using a routing file. Route all traffic through index.php, then have index.php decide on basis of the slug which file to reroute it to. – Tschallacka Apr 23 '18 at 08:45
  • @CBroe - Basically have to keep creating a copy of the file with a new name and rewrite the old one each time this happens... When I posted this question first it had been called accountcreation.php which I had to create a copy of called create.php and add a rewite rule to handle this, as you can see in the first snippet of the htaccess file. This happened again this morning and I created yet another copy of the file which is now working called creation.php and had to add yet another line to the htaccess and point them all to this new file as you can see in the edit – Paddy Hallihan Apr 23 '18 at 08:46
  • _“and add a rewite rule to handle this, as you can see in the first snippet of the htaccess file”_ - yeah, only you didn’t. None of those rules would match `accountcreation.php` – CBroe Apr 23 '18 at 08:47
  • @CBroe After that file stopped working the copy I created was called create.php and then I added `RewriteRule ^accountcreation/?$ create.php [L,NC,QSA]` now create.php has the error and I created a copy called creation.php and added `RewriteRule ^create/?$ creation.php [L,NC,QSA]`. See new screenshot – Paddy Hallihan Apr 23 '18 at 08:54
  • @CBroe basically I have to keep rewriting my htaccess to handle the error what you're looking at is how it is temporarily resolved each time – Paddy Hallihan Apr 23 '18 at 08:57
  • @CBroe my htaccess is now rewriting all of the files names that don't work to the new copy that is working as intended called creation.php previously create.php and before that accountcreation.php. When I remove any of these lines and try to go to any of those urls I get the error even though those files were never removed. – Paddy Hallihan Apr 23 '18 at 09:01

1 Answers1

1

This was resolved by contacting my shared domain host.

Although technically there was nothing wrong with the file and it worked as intended, it was being marked as malicious by the domain host.

I am still waiting to see if they can give more information about why this was seen as malicious.

Paddy Hallihan
  • 1,624
  • 3
  • 27
  • 76
  • This is caused by you having a `mail()` call shared hosts are noobs like that they block everything they get an email about instead of reading the email from there cPanel Control panel they just click the block button, you should move to using something like mailgun so your not using the servers mailer and using your own. – Barkermn01 Apr 26 '18 at 18:36
  • No that's not it, I've other mail() functions working fine in other parts of the site. I changed it so that all the parsing was nested inside the previous bit and got rid of the $parsed variable and that seems to have done the trick (although this makes no sense to me as to why it'd be considered malicious). – Paddy Hallihan Apr 27 '18 at 08:14
  • This happened to me. I was sending a POST of about 1 Mb size, and it was getting marked as spam on the hoster side, so all responses were 410. After few attempts, my IP got banned and unbanned about an hour later (I can tell exactly). I could not even access other sites on the same shared machine (sites of other clients, not just me)!! I solved by contacting my hoster support. – FonzTech Jan 13 '21 at 10:22