Advertisement
Guest User

Untitled

a guest
May 12th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. Puoi fare tutto con una semplice post lato client e gestirla sul tuo server lato php:
  2.  
  3. [CODE]
  4. Private Sub checkOnline(bool inEsecuzione)
  5. Dim s As HttpWebRequest
  6. Dim enc As UTF8Encoding
  7. Dim postdata As String
  8. Dim postdatabytes As Byte()
  9. s = HttpWebRequest.Create("http://www.tuosito.com/check.php")
  10. enc = New System.Text.UTF8Encoding()
  11.  
  12. if(inEsecuzione)
  13. postdata = "start=1"
  14. else
  15. postdata = "start=0"
  16.  
  17. postdatabytes = enc.GetBytes(postdata)
  18. s.Method = "POST"
  19. s.ContentType = "application/x-www-form-urlencoded"
  20. s.ContentLength = postdatabytes.Length
  21.  
  22. Using stream = s.GetRequestStream()
  23. stream.Write(postdatabytes, 0, postdatabytes.Length)
  24. End Using
  25. Dim result = s.GetResponse()
  26. End Sub
  27. [/CODE]
  28.  
  29. All'avvio del software:
  30.  
  31. [CODE]checkOnline(true)[/CODE]
  32.  
  33. Al termine del software:
  34.  
  35. [CODE]checkOnline(false)[/CODE]
  36.  
  37.  
  38. Codice PHP (check.php):
  39.  
  40. [CODE]
  41. <?php
  42.  
  43. $file = "/tuofile.txt";
  44.  
  45. if (isset($_POST["start"]))
  46. {
  47. //Ti recuperi il valore della POST
  48. $connesso = intval($_POST["start"]);
  49.  
  50. if (connesso == 1)
  51. {
  52. //Aggiungi al counter nel file txt
  53. $numUtentiConnessi = intval(file_get_contents($file));
  54. $numUtentiConnessi += 1;
  55. file_put_contents($file, $numUtentiConnessi);
  56. }
  57. else
  58. {
  59. //Utente disconnesso sottrai dal counter nel file txt
  60. $numUtentiConnessi = intval(file_get_contents($file));
  61. $numUtentiConnessi -= 1;
  62. file_put_contents($file, $numUtentiConnessi);
  63. }
  64. }
  65. else
  66. exit();
  67. ?>
  68.  
  69. [/CODE]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement