for date and time print some functions

for date various like

Example :<br />

echo “The current date is “;
echo date(“l F d, Y”);

D = day like Mon
l = day like Monday
F = Month like June
M = Month like Jan starting 3 digit
d = date like 02
Y = year like 2021
y = year like last two digit 91/21

date(“N”); for week ka day niklana k liye like tuesday is 2;

date(“N”); for week no of day like monday is 1, tuesday is 2, wed is 3, thur is 4, friday is 5, sat is 6, sun is 7;

form Get AM/PM from time use like echo date(“H:i:sA”, strtotime($time));
form Get am/pm from time use like echo date(“H:i:sa”, strtotime($time));

for time

H = 24 hr format
h = 12 hr format
i = for minutes
s = for seconds
a = for am/pm
A = for AM/PM

ALL UK postcode

Download UK Postcodes with Latitude and Longitude
https://www.freemaptools.com/download-uk-postcode-lat-lng.htm
https://github.com/dwyl/uk-postcodes-latitude-longitude-complete-csv
php script
https://www.hashbangcode.com/article/converting-uk-postcode-longitude-and-latitude-php

Calculating distance

https://www.geodatasource.com/developers/php

https://martech.zone/calculate-distance/

SQL: Retrieving All Records Within A Range By Calculating Distance In Miles Using Latitude and Longitude

It’s also possible to use SQL to do a calculation to find all records within a specific distance. In this example, I’m going to query MyTable in MySQL to find all the records that are less than or equal to variable $distance (in Miles) to my location at $latitude and $longitude:

The query for retrieving all of the records within a specific distance by calculating distance in miles between two points of latitude and longitude are:

$query = "SELECT *, (((acos(sin((".$latitude."*pi()/180)) * sin((`latitude`*pi()/180)) + cos((".$latitude."*pi()/180)) * cos((`latitude`*pi()/180)) * cos(((".$longitude."- `longitude`)*pi()/180)))) * 180/pi()) * 60 * 1.1515) as distance FROM `table` WHERE distance <= ".$distance."

BASIC CRUD

<div style=”width:20%;border:1px solid;margin:0 auto;”><h3 style=”text-align:center;margin:0 2px;”>Web- Alliance Shortcut</h3><span style=”display:block;text-align:center;color:red;”>By: Shoeb Ahmad</span></div>
<?
if(!empty($_REQUEST[‘fields’])){
$fields = $_REQUEST[‘fields’];
$table_name = $_REQUEST[‘table_name’];
}
?>
<html>
<body>
<form method=”post” action=”” >
Fields
<textarea cols=”30″ rows=”4″ name=”fields” ><?php echo $fields;?></textarea>
DB table<input type=”text” name=”table_name” value=”<?php echo $table_name;?>”>
<input type=”submit” name=”add” value=”submit”>
</form>
</body>
</html>
<?
if($_REQUEST[‘add’] == “submit”){
$fields = $_REQUEST[‘fields’];
$table_name = $_REQUEST[‘table_name’];
echo “<form name=’form1′ id=’form1′>”;
foreach(explode(“,”,$fields) as $field){
echo $field.”&nbsp;&nbsp;”;
echo “<select name=’$field’>”;
echo “<option value=’id_field’>id</option>”;
echo “<option value=’text’>text</option>”;
echo “<option value=’select’>select</option>”;
echo “<option value=’multiselect’>multiselect</option>”;
echo “<option value=’radio’>radio</option>”;
echo “<option value=’checkbox’>checkbox</option>”;
echo “<option value=’textarea’>textarea</option>”;
echo “<option value=’date’>date</option>”;
echo “<option value=’keycode’>keycode</option>”;
echo “<option value=’time’>time</option>”;
echo “<option value=’amount’>amount</option>”;
echo “</select>”;
echo “<br>”;
}
echo “<br>”;
echo “<input type=’hidden’ name=’fields’ value='”.$fields.”‘>”;
echo “<input type=’hidden’ name=’table_name’ value='”.$table_name.”‘>”;
echo “<input type=’submit’ name=’create’ value=’submit’>”;
echo “</form>”;
}
?>
<?php
if($_REQUEST[‘create’] == “submit”){
$fields = $_REQUEST[‘fields’];

echo “<font color=’red’>################################################## START FORM ##################################################</font><br>”;
foreach($_REQUEST as $val=>$field){
//echo $val.”–>”.$field;
if($field == “id”) continue;
if($field == “id_field”) continue;
if($val == “create”) continue;
if($val == “fields”) continue;
if($val == “table_name”) continue;
$placeholder = ucwords(str_replace(“_”,” “, $val));
echo htmlentities(“<div class=\”form-group\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<label class=\”col-sm-2 control-label\” for=\”$placeholder\”>$placeholder</label>”).”<br>”;
if($field == “text”){
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<div class=\”col-sm-10\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<input type=\”$field\” id=\”$val\” name=\”$val\” class=\”form-control\” value=\”<?php echo $”.$val.”;?>\” placeholder=\”$placeholder\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“</div>”).”<br>”;
}else if($field == “select”){
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<div class=\”col-sm-10\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<?php echo $”.”grant->getCountyList(\”$val\”,\$”.$val.”,\”100%\”,false,\”form-control select2\”);?>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“</div>”).”<br>”;
}else if($field == “multiselect”){
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<div class=\”col-sm-10\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<?php echo $”.”grant->getCountyList(\”$val\”,\$”.$val.”,\”100%\”,true,\”form-control select2\”);?>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“</div>”).”<br>”;
}else if($field == “radio”){
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<div class=\”col-sm-10\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“No <input type=\”radio\” name=\”$val\” value=\”0\” class=\”flat-red $val\” <? echo (\$”.$val.” == 0) ? \”checked\” : \”\”; ?>>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“Yes <input type=\”radio\” name=\”$val\” value=\”1\” class=\”flat-red $val\” <? echo (\$”.$val.” == 1) ? \”checked\” : \”\”; ?>>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“</div>”).”<br>”;
}else if($field == “checkbox”){
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<div class=\”col-sm-10\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<input type=\”checkbox\” class=\”flat-red\” id=\”$val\” name=\”$val\” value=\”1\” <? echo (\$”.$val.” == 1) ? \”checked\” : \”\”; ?>>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“</div>”).”<br>”;
}else if($field == “textarea”){
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<div class=\”col-sm-10\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<textarea class=\”form-control\” rows=\”3\” id=\”$val\” name=\”$val\” placeholder=\”$placeholder\”><?php echo stripslashes(\$”.$val.”);?></textarea>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“</div>”).”<br>”;
}else if($field == “date”){
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<div class=\”col-sm-10\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<input type=\”text\” class=\”form-control datepicker\” id=\”$val\” name=\”$val\” value=\”<?php (isset(\$”.$val.”) && \$”.$val.” !=\”\”) ? utility::getFormatedDate(\$”.$val.”) : \”\”;?>\” placeholder=\”$placeholder\” autocomplete=\”off\” >”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“</div>”).”<br>”;
}else if($field == “keycode”){
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<div class=\”col-sm-10\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<? echo Keycode::getKeycodeListValue(\”$val\”, \$”.$val.”, \$width = \”100%\”, \”$placeholder\”, \”id\”, \”code\”, \”$val\”,\”\”,\”form-control select2\”); ?>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“</div>”).”<br>”;
}else if($field == “time”){
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<div class=\”col-sm-10\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<div class=\”bootstrap-timepicker\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<input type=\”$field\” id=\”$val\” name=\”$val\” class=\”form-control timepicker\” value=\”<?php echo $”.$val.”;?>\” placeholder=\”$placeholder\” autocomplete=\”off\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“</div>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“</div>”).”<br>”;
}else if($field == “amount”){
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<div class=\”col-sm-10\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“<input type=\”$field\” id=\”$val\” name=\”$val\” class=\”form-control\” value=\”<?php echo ($”.$val.” != 0) ? $”.$val.” : \”\”;?>\” placeholder=\”$placeholder\”>”).”<br>”;
echo “&nbsp;&nbsp;&nbsp;&nbsp;”.htmlentities(“</div>”).”<br>”;
}
echo htmlentities(“</div>”).”<br>”;
}
echo “<font color=’red’>################################################## END FORM ##################################################</font><br><br>”;

$insert_values = “”;
$update_values = “”;
$tab = “&nbsp;&nbsp;&nbsp;&nbsp;”;
echo “<font color=’red’>################################################## START INSERT ##################################################</font>”;
echo “<br>”;
echo “if(isset($”.”_REQUEST[‘action’]) && $”.”_REQUEST[‘action’] == ‘insert’){“;
echo “<br>”;
echo $tab.”utility::addslashesOnAllInput(array(\”query_string\”));”.”<br>”;
echo “<br>”;
//foreach(explode(“,”,$_REQUEST[‘fields’]) as $field){
foreach($_REQUEST as $field=>$val){
if($field == “id”) continue;
if($field == “create”) continue;
if($field == “fields”) continue;
if($field == “table_name”) continue;

$field = trim($field);
if(empty($field)) continue;
if($val == “date”){
echo “$tab$”.$field.” = utility::setFormatedDate($”.”_REQUEST[‘$field’]);<br>”;
}elseif($val == “multiselect”){
echo “$tab$”.$field.” = implode(\”,\”,$”.”_REQUEST[‘$field’]);<br>”;
}else{
echo “$tab$”.$field.” = $”.”_REQUEST[‘$field’];<br>”;
}
$insert_values.=”‘$”.$field.”‘,”;
}
echo “$tab\$created_on = date(\”Y-m-d\”);<br>”;
echo “$tab\$updated_by = \$_SESSION[\”user_id\”];<br>”;
$insert_values = substr($insert_values,0,-1);

echo “<br>”;
echo “$tab$”.”sql= \”INSERT INTO $”.”table_name ($fields,created_on,updated_by) VALUES($insert_values,’\$created_on’,’\$updated_by’)\”;”;
echo “<br>”;
echo $tab.”mysql_query($”.”sql);”;
echo “<br>”;
echo “<br>”;
echo $tab.”\$_SESSION[‘info_message’] = \””.ucfirst(str_replace(“_”,” “,$table_name)).” added sucessfully\”;”;
echo “<br>”;
echo $tab.”header(\”Location: $”.”file_name\”);”;
echo “<br>”;
echo $tab.”exit();”;
echo “<br>”;
echo “}”;
echo “<br>”;

echo “<font color=’red’>################################################# END INSERT #################################################</font><br>”;

echo “<font color=’red’><br>################################################## START EDIT ##################################################</font>”;
echo “<br>”;
echo “if(isset($”.”_REQUEST[‘action’]) && $”.”_REQUEST[‘action’] == ‘edit’){“;
echo “<br>”;
echo “<br>”;
echo $tab.”$”.”id = $”.”_REQUEST[‘id’];”.”<br>”;
echo $tab.”$”.”form_action = \”update\”;”.”<br>”;
echo $tab.”$”.”button_value = \”Update\”;”.”<br>”;
echo $tab.”$”.”page_name = \”Edit “.ucfirst(str_replace(“_”,” “,$table_name)).”\”;”.”<br><br>”;
echo $tab.”$”.”query_string = (isset(\$_POST[‘query_string’])) ? \$_POST[‘query_string’] : \$_SERVER[‘QUERY_STRING’];”;

echo “<br><br>”;
echo “$tab$”.”sql= \”SELECT * FROM \$table_name WHERE id = ‘\$id’ \”;”;
echo “<br>”;
echo $tab.”$”.”result_edit = mysql_query($”.”sql);”;
echo “<br>”;
echo $tab.”$”.”row_edit = mysql_fetch_array($”.”result_edit);”;
echo “<br><br>”;
foreach($_REQUEST as $field=>$val){
if($field == “id”) continue;
if($field == “create”) continue;
if($field == “fields”) continue;
if($field == “table_name”) continue;

$field = trim($field);
if(empty($field)) continue;
if($val == “multiselect”){
echo “$tab$”.$field.”= explode(\”,\”,$”.”row_edit[‘$field’]);<br>”;
}else{
echo “$tab$”.$field.”= $”.”row_edit[‘$field’];<br>”;
}
$insert_values.=”‘$”.$field.”‘,”;
}
$insert_values = substr($insert_values,0,-1);
echo “}”;
echo “<br>”;
echo “<font color=’red’> ################################################# END EDIT #################################################</font>”;

echo “<font color=’red’> <br><br>################################################## START UPDATE ################################################## </font>”;
echo “<br>”;
echo “if(isset($”.”_REQUEST[‘action’]) && $”.”_REQUEST[‘action’] == ‘update’){“;
echo “<br>”;
echo $tab.”utility::addslashesOnAllInput(array(\”query_string\”));”.”<br>”;
echo “<br>”;
echo “$tab”.”\$id = \$_REQUEST[‘id’];<br>”;
foreach($_REQUEST as $field=>$val){
if($field == “id”) continue;
if($field == “create”) continue;
if($field == “fields”) continue;
if($field == “table_name”) continue;
$field = trim($field);
if(empty($field)) continue;

if($val == “date”){
echo “$tab$”.$field.” = utility::setFormatedDate($”.”_REQUEST[‘$field’]);<br>”;
}elseif($val == “multiselect”){
echo “$tab$”.$field.” = implode(\”,\”,$”.”_REQUEST[‘$field’]);<br>”;
}else{
echo “$tab$”.$field.” = $”.”_REQUEST[‘$field’];<br>”;
}
//echo “$tab$”.$field.”= $”.”_REQUEST[‘$field’];<br>”;
//$insert_values.=”‘$”.$field.”‘,”;

//echo “$”.$field.”= $”.”_REQUEST[‘$field’];<br>”;
$update_values.= “$field = ‘$”.$field.”‘, “;

}
echo “$tab\$updated_by = \$_SESSION[\”user_id\”];<br>”;

$update_values.= “updated_by = ‘\$updated_by’ “;
//$update_values = substr($update_values,0,-2);

echo “<br>”;
echo “$tab$”.”sql= \”UPDATE \$table_name SET $update_values WHERE id = ‘\$id’ \”;”;
echo “<br>”;
echo $tab.”mysql_query($”.”sql);”;
echo “<br><br>”;
echo $tab.”$”.”query_string = (isset(\$_REQUEST[‘query_string’]) && !empty(\$_REQUEST[‘query_string’])) ? \$_REQUEST[‘query_string’] : \”\”;”.”<br>”;
echo $tab.”$”.”query_string = str_ireplace(\”page=add\”, \”page=view\”, \$query_string);”.”<br>”;
echo $tab.”$”.”query_string = \”&\”.\$query_string;”.”<br>”;
echo “<br>”;
echo $tab.”\$_SESSION[‘info_message’] = \””.ucfirst(str_replace(“_”,” “,$table_name)).” updated sucessfully\”;”;
echo “<br>”;
echo $tab.”header(\”Location: $”.”file_name\”);”;
echo “<br>”;
echo $tab.”exit();”;
echo “<br>”;
echo “}”;
echo “<br>”;
echo “<font color=’red’> ################################################# END UPDATE #################################################</font>”;

echo “<font color=’red’> <br><br>################################################## START DELETE ##################################################</font>”;
echo “<br>”;
echo “if(isset($”.”_REQUEST[‘action’]) && $”.”_REQUEST[‘action’] == ‘delete’){“;
echo “<br>”;
echo “<br>”;
echo $tab.”$”.”id = $._REQUEST[‘id’];”;
echo “<br>”;
echo $tab.”$”.”sql= \”DELETE FROM \$table_name WHERE id = ‘\$id’ \”;”;
echo “<br>”;
echo $tab.”mysql_query($”.”sql);”;
echo “<br><br>”;
echo $tab.”\$_SESSION[‘info_message’] = \””.ucfirst(str_replace(“_”,” “,$table_name)).” deleted sucessfully\”;”;
echo “<br>”;
echo $tab.”header(\”Location: $”.”file_name\”);”;
echo “<br>”;
echo $tab.”exit();”;
echo “<br>”;
echo “}”;
echo “<br>”;
echo “<font color=’red’>################################################# END DELETE #################################################</font><br><br>”;

echo “<font color=’green’>################################################# START CREATE TABLE #################################################</font><br><br>”;
$create_table = “”;
$create_table .= “CREATE TABLE IF NOT EXISTS `$table_name` (“.”<br>”;
$create_table .= “`id` int(11) NOT NULL AUTO_INCREMENT,”.”<br>”;
foreach($_REQUEST as $field=>$val){
if($field == “id”) continue;
if($field == “create”) continue;
if($field == “fields”) continue;
//if($field == “table_name”) continue;
$field = trim($field);
if(empty($field)) continue;

if($val == “id_field”){
$create_table .= “`$field` int(11) NOT NULL,”.”<br>”;
}elseif($val == “text”){
$create_table .= “`$field` varchar(255) NOT NULL,”.”<br>”;
}elseif($val == “select”){
$create_table .= “`$field` int(11) NOT NULL,”.”<br>”;
}elseif($val == “multiselect”){
$create_table .= “`$field` varchar(100) NOT NULL,”.”<br>”;
}elseif($val == “radio”){
$create_table .= “`$field` tinyint(4) NOT NULL,”.”<br>”;
}elseif($val == “checkbox”){
$create_table .= “`$field` tinyint(4) NOT NULL,”.”<br>”;
}elseif($val == “textarea”){
$create_table .= “`$field` text NOT NULL,”.”<br>”;
}elseif($val == “date”){
$create_table .= “`$field` datetime NOT NULL,”.”<br>”;
}elseif($val == “keycode”){
$create_table .= “`$field` int(11) NOT NULL,”.”<br>”;
}elseif($val == “time”){
$create_table .= “`$field` time NOT NULL,”.”<br>”;
}elseif($val == “amount”){
$create_table .= “`$field` double NOT NULL,”.”<br>”;
}

}
//$create_table = substr($create_table,0,-2);
$create_table .= “`created_on` datetime NOT NULL,”.”<br>”;
$create_table .= “`updated_by` int(11) NOT NULL,”.”<br>”;
$create_table .= “`updated_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,”.”<br>”;
$create_table .= “PRIMARY KEY (`id`)”.”<br>”;
$create_table .= ” );”;
echo $create_table;
echo “<br><br><font color=’green’>################################################# END CREATE TABLE #################################################</font>”;
}
?>

Remove Via server or any warning from php mail function

Yes, you can get rid the “via” part. Here’s the details:

1) SPF and DKIM
Firstly, you would need to set an SPF record for the domain you are sending emails from and enable DKIM as well. These are primarily for identifying your messages against spam.

2) “From: anything@yourdomain.com”
Secondly, make sure you are setting the “From: ” header to be an email address on the domain you are sending messages from. Don’t pretend to be someone else. Use “From: someone@abc.com” if you are sending the messages from abc.com, rather than anything else, such as blah@def.com, or yours@gmail.com, or whatever. If you want the recipient to reply to your Gmail email instead of your domain email, use the “Reply-To: ” header. “From: ” must always be the domain email that you are sending the email from.

3) “Return-Path: return@yourdomain.com”
Thirdly and most importantly, set the “Return-Path: ” header to be the same domain as that of the “From: ” header. Use the 5th parameter of the mail() function for this:

mail(‘recipient@example.com’, ‘Subject’, “Message Body”, $headers, ‘-freturn@yourdomain.com’)
So the Return-Path of this message would be “return@yourdomain.com” (the email address immediately following the -f switch). The $headers parameter should contain all the necessary message headers. Make sure “From: ” is something@yourdomain.com.

After these steps and measures, Gmail should now completely trust your messages from yourdomain.com. The ‘via‘ field of your messages should be gone and the ‘mailed-by‘ field as well as the ‘signed-by‘ field should be correctly showing up as yourdomain.com.

Hope it helps!

Finding links from within a string in PHP

$text '<a href="www.google.com">google.com</a>General email: <a href="mailto:enquiries@thegaragedoorcentre.co.uk">enquiries@thegaragedoorcentre.co.uk</a>

<a href="www.google2.com">google.com</a>
<a href="www.google3.com">google.com</a>

&nbsp;

';
preg_match_all('~href=("|\')(.*?)\1~', $text, $out);

echo "<pre>";
print_r($out);
die;