Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [opinie] request security
Spawnm
post
Post #1





Grupa: Moderatorzy
Postów: 4 069
Pomógł: 497
Dołączył: 11.05.2007
Skąd: Warszawa




Hej,
luźny temat z pytaniem co myślicie to tej małej klasie:
Jej zadaniem ma być sprawdzenie jeszcze w bootstrapie czy akcje zadań są wykonywane przez usera a nie bota itd.

  1. /**
  2. * @author Spawnm
  3. * @license New BSD License
  4. */
  5. class security_request
  6. {
  7. /**
  8.   * @param array $data
  9.   */
  10. public function initGET(array $data)
  11. {
  12. if($_GET){
  13. foreach($data as $key){
  14. if( isset($_GET[ $key ] ) && !isset($_SERVER['HTTP_REFERER'] )){
  15. throw new Exception('initGET: security failed.');
  16. }
  17. if( isset($_GET[$key]) && !$this->refererIsLocal() ){
  18. throw new Exception('initGET: security failed.');
  19. }
  20. }
  21. }
  22. }
  23.  
  24. /**
  25.   * @return bool
  26.   */
  27. public function refererIsLocal()
  28. {
  29. $host = parse_url($_SERVER['HTTP_REFERER']);
  30. $host = $host['host'];
  31. $local = $_SERVER['HTTP_HOST'];
  32. return ($host === $local )? true : false;
  33. }
  34.  
  35. /**
  36.   * @param array $data
  37.   */
  38. public function initPOST(array $data)
  39. {
  40. if($_POST){
  41. foreach($data as $key){
  42. if( isset($_POST[ $key ] ) && !isset($_SERVER['HTTP_REFERER'] )){
  43. throw new Exception('initPOST: security failed.');
  44. }
  45. if( isset($_POST[$key]) && !$this->refererIsLocal() ){
  46. throw new Exception('initPOST: security failed.');
  47. }
  48. }
  49. }
  50. }
  51.  
  52. }


Demo:
  1. $sec= new security_request();
  2. $sec->initGET(array('delete', 'edit', 'add'));
  3. $sec->initPOST(array('add', 'edit', 'id', 'captcha'));

Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 26.09.2025 - 02:40