Advertisement
Guest User

Untitled

a guest
Feb 21st, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $erronoacesso = '';
  4.  
  5. $user = NULL;
  6. $pass = NULL;
  7.  
  8. if (isset($_SERVER['user'], $_SERVER['pass'])) {
  9. $user = $_SERVER['user'];
  10. $pass = $_SERVER['pass'];
  11. } else {
  12. if (!isset($_SERVER['PHP_AUTH_USER'])) {
  13. header('WWW-Authenticate: Basic realm="My Realm"');
  14. header('HTTP/1.0 401 Unauthorized');
  15. $erronoacesso = 'Cancelado';
  16. } else {
  17. $user = $_SERVER['PHP_AUTH_USER'];
  18. $pass = $_SERVER['PHP_AUTH_PW'];
  19. }
  20. }
  21.  
  22. if (isset($user, $pass)) {
  23. $mysqli = new mysqli('SEU SERVIDOR', $user, $pass, 'SEU BANCO');
  24.  
  25. if ($mysqli->connect_errorno) {
  26. $erronoacesso = 'Acesso negado: ' . $mysqli->connect_error;
  27. }
  28. }
  29.  
  30. <?php
  31.  
  32. require_once 'conexao.php';
  33.  
  34. if (false === empty($erronoacesso)) {
  35. echo 'Erro: ', $erronoacesso;
  36. } else {
  37. //Mysql
  38. $mysqli->...
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement