Advertisement
Guest User

Untitled

a guest
May 21st, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <?php
  2. header("Access-Control-Allow-Origin: *");
  3. header("Content-Type: Application/json");
  4. session_start();
  5. if(isset($_GET['nome']) && isset( $_GET['password'])){
  6. $nome = $_GET['nome'];
  7. $password= $_GET['password'];
  8. $servername="127.0.0.1";
  9. $dbname="my_portalsdragon";
  10. $username="portalsdragon";
  11. $pass="";
  12. try{
  13. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $pass);
  14. // set the PDO error mode to exception
  15. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  16. function conNom ($conn,$nome){
  17. $stmt = $conn->prepare("SELECT count(*) FROM studente where username = :nome");
  18. $stmt->bindParam(':nome', $nome);
  19. $stmt->execute();
  20. return $stmt->fetchColumn();
  21.  
  22.  
  23.  
  24. }
  25. if(conNom($conn,$nome)!=0){
  26. $stmt = $conn->prepare("SELECT nome, cognome, username, pass, cod_fis FROM studente where username = :nome and pass = password(:password)");
  27. $stmt->bindParam(':nome', $nome);
  28. $stmt->bindParam(':password', $password);
  29. $stmt->execute();
  30.  
  31. // set the resulting array to associative
  32. $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
  33. /*foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
  34. echo $v;
  35. }*/
  36. echo json_encode($result);
  37. $_SESSION["JSONSTUDENTE"]=$result;
  38.  
  39. }
  40. else {
  41. $coso='errore';
  42. echo json_encode($coso);
  43.  
  44. }}
  45. catch(PDOException $e)
  46. {
  47. echo "Error: " . $e->getMessage();
  48. }
  49.  
  50. }else{
  51. echo "setta il nome";
  52. }
  53.  
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement