Last active
March 25, 2025 10:26
-
-
Save Shakil-Shahadat/5ee21ddc3a18466fc11ec28d60674418 to your computer and use it in GitHub Desktop.
★ Miscellaneous PHP Codes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//------------------------------------------------------- | |
// Send Email | |
//------------------------------------------------------- | |
$to = '[email protected]'; | |
$subject = 'Test mail'; | |
$message = 'Hello! This is a simple email message.'; | |
$from = '[email protected]'; | |
$header = 'From: ' . $from; | |
mail( $to, $subject, $message, $header ); | |
echo 'Mail Sent.'; | |
// ToDo: See if mail() returns anything. If so, improve this example. | |
//------------------------------------------------------- | |
// Escape $_GET / $_POST Array | |
//------------------------------------------------------- | |
// For MySQL | |
// Escape $_GET elements | |
foreach ( $_GET as $key => $value ) | |
{ | |
$_GET[ $key ] = $db->escape_string( $_GET[ $key ] ); | |
} | |
// Escape $_POST elements | |
foreach ( $_POST as $key => $value ) | |
{ | |
$_POST[ $key ] = $db->escape_string( $_POST[ $key ] ); | |
} | |
// For SQLite | |
// Escape $_GET elements | |
foreach ( $_GET as $key => $value ) | |
{ | |
$_GET[ $key ] = $db->escapeString( $_GET[ $key ] ); | |
} | |
// Escape $_POST elements | |
foreach ( $_POST as $key => $value ) | |
{ | |
$_POST[ $key ] = $db->escapeString( $_POST[ $key ] ); | |
} | |
//------------------------------------------------------- | |
// Miscellaneous | |
//------------------------------------------------------- | |
// Todays' date in the format 20XX-XX-XX | |
echo date( 'Y-m-d' ); | |
// Todays' date in the format XX-XX-XX hour:min:sec | |
echo date( 'y-m-d h:i:sa' ); | |
// Decode 'encodeURIComponent' encoded string | |
urldecode( ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment