Calculating distance between zip codes in PHP

This is mike’s answer with some annotations for the magic numbers. It seemed to work fine for me for some test data: function calc_distance($point1, $point2) { $radius = 3958; // Earth’s radius (miles) $deg_per_rad = 57.29578; // Number of degrees/radian (for conversion) $distance = ($radius * pi() * sqrt( ($point1[‘lat’] – $point2[‘lat’]) * ($point1[‘lat’] – … Read more

What is the best way to password protect folder/page using php without a db or username

Edit: SHA1 is no longer considered secure. Stored password hashes should also be salted. There are now much better solutions to this problem. You could use something like this: //access.php <?php //put sha1() encrypted password here – example is ‘hello’ $password = ‘aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d’; session_start(); if (!isset($_SESSION[‘loggedIn’])) { $_SESSION[‘loggedIn’] = false; } if (isset($_POST[‘password’])) { if … Read more

Escape string to use in mail()

The idea behind email-injection is that attacker inject line feed (LF) in the email headers and so he adds as many headers as he wants. Stripping those line feeds will protect you from this attack. For detailed info check The best practice is to rely on a well-written, frequently updated and widely-used code. For … Read more

how to pass an array in GET in PHP?

If you want to pass an array as parameter, you would have to add a parameter for each element. Your query string would become: ?arr[]=1&arr[]=2&arr[]=3&arr[]=4 As others have written, you can also serialize and unserialize the array. But do you really have to send the data to the client again? It looks like you just … Read more