Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #11 from dbursem/master
Fixed SQL injection vulnerabilities by using PDO statements
- Loading branch information
Showing
4 changed files
with
81 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| .idea | ||
| config.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?php | ||
|
|
||
| $cfg = [ | ||
| "db_type" => 'mysql', | ||
| "db_host" => 'localhost', | ||
| "db_user" => '', | ||
| "db_pass" => '', | ||
| "db_name" => '', | ||
| ]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,29 @@ | ||
| <?php | ||
| function ouvrebase() | ||
| { | ||
| // **************** Connexion et ouverture de la base ************************ | ||
| global $link; | ||
| //if (!($link = @mysql_connect( ))) // en local | ||
| if (!($link = @mysql_connect("****hostname****", "****username****", "****password****" ))) // | ||
| { | ||
| include 'config.php'; | ||
|
|
||
| try | ||
| { | ||
| $dbh = new PDO($cfg['db_type'].':host='.$cfg['db_host'].';dbname='.$cfg['db_name'], $cfg['db_user'], $cfg['db_pass']); | ||
| $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | ||
| } | ||
| catch (PDOException $e) { | ||
| echo 'Connection failed: ' . $e->getMessage(); | ||
| } | ||
|
|
||
| //legacy mysql_connect for non-released code: | ||
|
|
||
| $link; | ||
| if (!($link = @mysql_connect($cfg['db_host'], $cfg['db_user'], $cfg['db_pass'] ))) // | ||
| { | ||
| echo "<BR><BR><CENTER>Connection not possible</CENTER><BR><BR>"; | ||
| @mysql_close($link); | ||
| exit(); | ||
| } | ||
| } | ||
|
|
||
| if (!(@mysql_select_db ("****databasename****",$link))) | ||
| { | ||
| if (!(@mysql_select_db ($cfg['db_name'],$link))) | ||
| { | ||
| echo "<BR><BR><CENTER>Database access not possible</CENTER><BR><BR>"; | ||
| @mysql_close($link); | ||
| exit(); | ||
| } | ||
| // *************************************************************************** | ||
|
|
||
| } | ||
| ?> | ||
| } | ||
| // *************************************************************************** |