0

I read a lot about mysql security, and php script security and was just wondering if this would suit to prevent from intrusions. I made script config.php, and register.php witch are stored in folder that is above root folder ( example ../project/script/ and ../project/www/)

register.php looks like this:

<?php

require_once 'db_config.php';
$user=$_GET['username'];
$pass=$_GET['password'];
$db=$_GET['company']; 
try {
    $dbh = new PDO("mysql:host=$host", $username, $password);//connecting to        database
    //check if database exists
    $stmt = $dbh->query("SELECT COUNT(*) FROM INFORMATION_SCHEMA.SCHEMATA   WHERE SCHEMA_NAME = '$db'");
    if($stmt->fetchColumn() == 1){
    //some code
    }else{
        $dbh->exec("CREATE DATABASE `$db`;
                    CREATE USER '$user'@'localhost' IDENTIFIED BY '$pass';
                    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `$db`.* TO '$user'@'localhost';
                    FLUSH PRIVILEGES;") or die(print_r($dbh->errorInfo(), true));
        echo 'DB created';
    }   

}
 catch (PDOException $e) {
    die("DB ERROR: ". $e->getMessage());
}
?>

and test.php looks like this:

<?php
include ('../scripts/db_connect.php');
include ('../scripts/register.php');
?>

My question would be is this good coding practice, will it be secure from someone messing up my database, and what in general do you have to point out to have better looking code in general?? Also any materials on how code should look so other can read it and PHP SQL safety would be appreciated.

Flimzy
  • 60,850
  • 13
  • 104
  • 147
  • 1
    I'm voting to close this question as off-topic because it belongs on codereview.stackexchange.com – e4c5 Sep 30 '16 at 13:08
  • it is open to an sql injection; use a prepared statement – Funk Forty Niner Sep 30 '16 at 13:09
  • You might also want to reconsider this `$pass=$_GET['password'];` you're URL-passing the password which would virtually negate the whole purpose of putting the thing under HTTPS - which it should be with any login script. – CD001 Sep 30 '16 at 13:14

0 Answers0