Welcome to W3Courses
 Like Us on Facebook

PHP

Add an Automatic / Dynamic Copyrighted Year Message in PHP

Instead of manually updating the copyrighted message every year, you can add a dynamic and automatic copyrighted year message at the bottom of your website. To do so, include the following code at the bottom of your php files just before the body tag.

<?
      $year= date('Y');
      echo("Copyrighted &copy;$year W3courses.com");
?>

Share

Php Mail Function with Html Header

I recenltly used the php mail function.  Simple but useful.

http://www.php.net/function.mail

Share

How to check if an email address exists without sending an email?

We have all been doing email address validation for a very long time to make sure that the email is correctly formatted. This is to avoid users entering wrongly formatted email address but still they can accidentally give us a wrong email address.

Example of a correctly formatted email address but still wrong:

mailbox.does.not.exist@reddit.com [VALID email fromat but still not correct]

Share

Pass Array from Multipart/Form-data Post Method or Query String with Foreach Function in PHP

You can have your form build an array of mutiple text box values and then pass it. The problem is that is global variables are on, it will work but if global variables are off you will have to retrieve each element like the following. If you are using the query string, replace $_Post with $_Get

<?php

echo("<form name='multiupload' enctype='multipart/form-data' method='post' action='{$_SERVER['PHP_SELF']}'>");

Share

Use in_array function to check if a value exists in an array using PHP

You can use in_array function to check if a value exists in an array:

For example:

<?php

$myname = "David";

$names = array("Paul","Maria","David","Lucy","Ana");

if (in_array($myname, $names))
       echo("Welcome $myname");
else
      echo "Sorry, that is not a valid name";

?>
 

Share

Loop through an Array using Foreach Function in PHP

You can loop through an array using foreach function. So instead of using:

<?php

$names = array("Paul","Maria","David","Lucy","Ana");

$i=0
while($names[$i] == true)
{
     echo("$names[$i]");
     $i++;
}

?>
 


You can be more efficient and use foreach:

<?php

Share

Delete File or an Image from the Server using PHP

If you want to delete a file or an image from the server via an interface from you website, you can use the following code

<?php

function deletemyfile($filename)
{

 $filearray = explode("/", $filename);

 $filecountno = count($filearray);
 $filecountno = $filecountno-1;
 for($i=0;$i<=$filecountno;$i++)
 {
  $myfilename = $filearray[$i];
 }

Share

Encrypt Decrypt using the Rijndael 256 Mcrypt Function in PHP

You can encrypt and decrypt data using the Mcrypt function below:

<?

$mykey = "THISisMyKey";

Share

Encrypt Decrypt using the Rijndael 256 Mcrypt Class in PHP

You can encrypt and decrypt data using the following Mcrypt class:

<?

class pWord
{
    var $mykey = "THISisMyKey";

Share