digin1

config.php

Feb 6th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. <?php
  2. /***
  3. * @Source: devshed
  4. * @author E-Oreo
  5. * http://forums.devshed.com/php-faqs-stickies-167/program-basic-secure-login-system-using-php-mysql-891201.html
  6. */
  7. // These variables define the connection information for your MySQL database
  8. $username = "root";
  9. $password = "";
  10. $host = "localhost";
  11. $dbname = "clearsta_smt";
  12.  
  13. // UTF-8 is a character encoding scheme that allows you to conveniently store
  14. // a wide varienty of special characters, like ยข or โ‚ฌ, in your database.
  15. // By passing the following $options array to the database connection code we
  16. // are telling the MySQL server that we want to communicate with it using UTF-8
  17. // See Wikipedia for more information on UTF-8:
  18. // http://en.wikipedia.org/wiki/UTF-8
  19. $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
  20.  
  21. // A try/catch statement is a common method of error handling in object oriented code.
  22. // First, PHP executes the code within the try block. If at any time it encounters an
  23. // error while executing that code, it stops immediately and jumps down to the
  24. // catch block. For more detailed information on exceptions and try/catch blocks:
  25. // http://us2.php.net/manual/en/language.exceptions.php
  26. try
  27. {
  28. // This statement opens a connection to your database using the PDO library
  29. // PDO is designed to provide a flexible interface between PHP and many
  30. // different types of database servers. For more information on PDO:
  31. // http://us2.php.net/manual/en/class.pdo.php
  32. $db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
  33. }
  34. catch(PDOException $ex)
  35. {
  36. // If an error occurs while opening a connection to your database, it will
  37. // be trapped here. The script will output an error and stop executing.
  38. // Note: On a production website, you should not output $ex->getMessage().
  39. // It may provide an attacker with helpful information about your code
  40. // (like your database username and password).
  41. die("Failed to connect to the database: " . $ex->getMessage());
  42. }
  43.  
  44. // This statement configures PDO to throw an exception when it encounters
  45. // an error. This allows us to use try/catch blocks to trap database errors.
  46. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  47.  
  48. // This statement configures PDO to return database rows from your database using an associative
  49. // array. This means the array will have string indexes, where the string value
  50. // represents the name of the column in your database.
  51. $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
  52.  
  53. // This block of code is used to undo magic quotes. Magic quotes are a terrible
  54. // feature that was removed from PHP as of PHP 5.4. However, older installations
  55. // of PHP may still have magic quotes enabled and this code is necessary to
  56. // prevent them from causing problems. For more information on magic quotes:
  57. // http://php.net/manual/en/security.magicquotes.php
  58. if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
  59. {
  60. function undo_magic_quotes_gpc(&$array)
  61. {
  62. foreach($array as &$value)
  63. {
  64. if(is_array($value))
  65. {
  66. undo_magic_quotes_gpc($value);
  67. }
  68. else
  69. {
  70. $value = stripslashes($value);
  71. }
  72. }
  73. }
  74.  
  75. undo_magic_quotes_gpc($_POST);
  76. undo_magic_quotes_gpc($_GET);
  77. undo_magic_quotes_gpc($_COOKIE);
  78. }
  79.  
  80. // This tells the web browser that your content is encoded using UTF-8
  81. // and that it should submit content back to you using UTF-8
  82. header('Content-Type: text/html; charset=utf-8');
  83.  
  84. // This initializes a session. Sessions are used to store information about
  85. // a visitor from one web page visit to the next. Unlike a cookie, the information is
  86. // stored on the server-side and cannot be modified by the visitor. However,
  87. // note that in most cases sessions do still use cookies and require the visitor
  88. // to have cookies enabled. For more information about sessions:
  89. // http://us.php.net/manual/en/book.session.php
  90. session_start();
  91.  
  92. // Note that it is a good practice to NOT end your PHP files with a closing PHP tag.
  93. // This prevents trailing newlines on the file from being included in your output,
  94. // which can cause problems with redirecting users.
  95.  
  96. ?>
Add Comment
Please, Sign In to add comment