Both functions includes the given file but Include_once() checks whether the given file is already included .As the name suggests , the file will be included only once .
Include() vs require()
include() will throw a warning and require() will throw a fatal error if the file is missing.
echo() vs print()
print() returns a value much like a normal function would but echo() does not
echo() runs faster than print()
Echo can take multiple parameters where as print cannot
Difference Between echo() and print() PHP
print() returns a value much like a normal function would but echo() does not
echo() runs faster than print()
Echo can take multiple parameters where as print cannot
Difference Between Include() and require() PHP
include() will throw a warning and require() will throw a fatal error if the file is missing.
Difference Between Include() and Include_once() PHP
Both functions includes the given file but Include_once() checks whether the given file is already included .As the name suggests , the file will be included only once .
CAPTCHA
A CAPTCHA is a type of challenge-response test used in computing as an attempt to ensure that the response is generated by a person. The process usually involves a computer asking a user to complete a simple test which the computer is able to grade. These tests are designed to be easy for a computer to generate, but difficult for a computer to solve, so that if a correct solution is received, it can be presumed to have been entered by a human. A common type of CAPTCHA requires the user to type letters or digits from a distorted image that appears on the screen, and such tests are commonly used to prevent unwanted internet bots from accessing websites.
The term “CAPTCHA” was coined in 2000 by Luis von Ahn, Manuel Blum, Nicholas J. Hopper, and John Langford (all of Carnegie Mellon University). It is an acronym based on the word “capture” and standing for “Completely Automated Public Turing test to tell Computers and Humans Apart”. Carnegie Mellon University attempted to trademark the term, but the trademark application was abandoned on 21 April 2008.
form validation
<?php
extract($_POST);
if(isset($_POST[‘send’])){
if(preg_replace(“/^s*$/”,””,$firstname)==”” )
$errorList[]=”Select the department name is required.”;
if(preg_replace(“/^s*$/”,””,$email)==”” )
$errorList[]=”Email is required.”;
elseif(!eregi(“^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$”, $email))
$errorList[] = “Email address is invalid.”;
if(preg_replace(“/^s*$/”,””,$message)==”” )
$errorList[]=”Message is required.”;
?>
<form action=”#” method=”post”>
<table>
<?php if(count($errorList)>0){ ?>
<tr>
<td> </td><td><div style=”margin:5px; color:#FF0000;”><?php foreach($errorList as $value) echo $value.” ,”; ?></div></td></tr>
<?php } ?>
<?php if($success==5){ ?>
<tr>
<td> </td> <td><div style=”margin:10px; color: #006633; width:90%; clear:none; float:left; font-weight:bold”>Your message has been sent to site admin .</div></td>
</tr>
<?php } ?>
<tr>
<td>Please enter your <strong>name</strong>:</td> <td><input name=”firstname” type=”text” value=”<?php echo $firstname ?>” /></td>
</tr>
<tr>
<td>Please enter your <strong>email address </strong>:</td> <td><input name=”email” type=”text” value=”<?php echo $email ?>” /></td>
</tr>
<tr>
<td>Please enter message:</td> <td><textarea name=”message” style=”height:50px;”><?php echo nl2br($message); ?></textarea></td>
</tr>
<tr>
<td> </td> <td><input type=”submit” name=”send” value=” Send “></td>
</tr>
</table>
cookie
Cookies can be used to store user information for future use . Cookies allow us to store data in users’ machine it self . Cookie is a small file that the server generate in user machine and using that file server can identify the user .When ever the browser send http request to the server , it send the cookies as well . Cookies can be created using PHP functions .
Cookies can be created using the function ‘ setcookie(name,Value ,exp,path,domain)’ and its arguments are given below
Name :Name of the cookie that store the value and it is using to retrieve the stored data
Value : Its the value to be stored in the cookie ()generally we store login details like username , password)
exp : This is the the time that cookie lasts . if its not set ,the cookie will get destroyed when the browser closed .
path : This is path where the cookie to be stored
Domain: Domain where the cookie to be generated
The following can be used to send a cookie from within a PHP application.
- header()
- setcookie()
- setrawcookie()
Example
======
<?php setcookie(“user_name”, “phpcodez”, time()+3600); ?>
You can retrieve the cookie values as follows
<?php echo $_COOKIE["user_name"]; ?>
You can delete the cookie by setting expiration date in the past
Example:
<?php setcookie(“user”, “”, time()-3600); ?>
session_destroy()
It delete/destroy existing session
<?php
session_start();
$_SESSION[‘lan’]=”PHP Code”;
echo $_SESSION[‘lan’] ;
session_destroy();
?>