ACCES INTERZIS | blog de programare si securitate IT




 06 2010 @ 19:42 

Scriptul PHP din spatele acestui formular de upload:

  • rezolva problema spatiilor goale din numele imaginii
  • restrictioneaza numarul maxim de caractere al numelui imaginii  si ce tip de caractere poate sa contina numele imaginii
  • permite utilizatorului sa uploadeze doar imagini (celelalte tipuri de fisiere, posibil malitioase, cum ar fi fisiere executabile, fisiere .php, fisiere .js nu pot fi urcate)
  • specifica ce tipuri de imagini pot fi uploadate (.jpg, .jpeg, .gif, .png)
  • restrictioneaza marimea maxima a imaginii
  • restrictioneaza latimea pe care o poate avea imaginea
  • restrictioneaza inaltimea pe care o poate avea imaginea
  • verifica daca folderul images exista pe server (daca nu exista il creaza)
  • verifica daca mai exista in folderul images inca o imagine cu acelasi nume
  • numeroteaza dinamic fiecare imagine uploadata (trebuie sa dam permisiile 0777 folderului images ca scriptul PHP sa il poata citi)
  • schimba numele imaginii uploadate pe server

Citeste tot articolul »

Post to Twitter Publica acest articol pe Twitter

Publicat de: admin
Ultima modificare: 17, 2010, 13:00
Comentarii: 0
Etichete
Etichete: ,
Categorii: programare
 22 Feb 2010 @ 17:41 

Scriptul PHP de mai jos extrage adrese de email de pe o pagina web.

<?php
$url = "http:/www.genericwebsite.com/contact.php";
//getting the source-code of the web page
$sc = file_get_contents($url);
$sc = strtolower($sc);
$forbidden_symbols = array('?', '!', ',', ';', ':', '+', '=', '/', '\\', '"', '\'', '`', '’', '“', '”', '#', '$', '%', '^', '&amp;', '*', '(', ')', '[', ']', '{', '}', '|', '<', '>');
//removing all symbols from the source-code less "@", "." and "_"
$sc = str_replace($forbidden_symbols, ' ', $sc);
//storing all words from the source-code into an array
$words_found = explode(' ', $sc);

//verifying each word from array if it is an email address
for ($i = 0; $i < count($words_found); $i++) {
	//if the word contains the symbols "@" that means it is an email address
	if (strpos($words_found[$i], '@')) {
		//I make sure that the email address has no empty spaces in the beginning and in the and of it
		$email_address = trim($words_found[$i]);

		//I make sure that the email address has no symbols in the beginning and in the and of it
		//I apply all these cleaning filters because the source-code can be pretty messy
		$first_char = substr($email_address, 0, 1);
		while (!ctype_alpha($first_char)) {
			$email_address = substr($email_address, 1, strlen($email_address));
			$first_char = substr($email_address, 0, 1);
		}

		$last_char = substr($email_address, strlen($email_address) - 1, 1);
		while (!ctype_alpha($last_char)) {
			$email_address = substr($email_address, 0, strlen($email_address) - 1);
			$last_char = substr($email_address, strlen($email_address) - 1, 1);
		}

		//I make sure that the extracted string is really an email address
		if (eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$", $email_address)) {
			echo $email_address.'<br />';
		}
	}
}
?>

Citeste tot articolul »

Post to Twitter Publica acest articol pe Twitter

Publicat de: admin
Ultima modificare: 01, 2010, 14:40
Comentarii: 23
Etichete
Etichete: ,
Categorii: programare