html5andphp

Monday, 5 August 2013

Cookies

Cookies


A cookie is often used to identify a user. Cookies are text files stored on the client computer and they are kept of use tracking purpose.

Each time the same computer requests a page with a browser, it will send the cookie too. PHP transparently supports HTTP cookies.

A cookie is a small file that the server embeds on the user's computer.
Server script sends a set of cookies to the browser.
such as user name ,password etc.
Browser stores this information on local machine for future use.

How to Create a Cookie?



** The setcookie() function must appear before the <html> tag.
setcookie(name, value, expire, path, domain, security);
 There are six arguments explain in detail below.

Name - This sets the name of the cookie and is stored in an environment variable called HTTP_COOKIE_VARS. This variable is used while accessing cookies.

Value -This sets the value of the named variable and is the content that you actually want to store.

Expiry – This specify a future time in seconds since 00:00:00 GMT on 1st Jan 1970. After this time cookie will become inaccessible. If this parameter is not set then cookie will automatically expire when the Web Browser is closed.

Path -This specifies the directories for which the cookie is valid. A single forward slash character permits the cookie to be valid for all directories.

Domain - This can be used to specify the domain name in very large domains and must contain at least two periods to be valid. All cookies are only valid for the host and domain which created them.

Security – This can be set to 1 to specify that the cookie should only be sent by secure transmission using HTTPS otherwise set to 0 which mean cookie can be sent by regular HTTP.
Syntax
setcookie(name, value, expire, path, domain,security);

Example
Generaly we use three orgument because of other three orgument used in web servers not in local machines.
<?php
setcookie("cookies_name", "umar farooque khan", time()+3600);
?>
<html>
<head>
.............
.............
</html>

Sunday, 4 August 2013

Changing image using php random function

Random function in image

In this code simpl use of random function and switch case.First of all random function call in switch case and pass the initial and final value of case such as no of cases =16( 1 to 16 ) then first orgument is 1 and second orgument is 16 and seprated by comma.Then starting a switch case curly braces  and then start the first case,make a variable which store the the image same as all cases and assign the image and then use break keyword (break is used for stop a particular case ,if you don't use break all the case excuted and all the values ).Lastly print the variable which store the image using html img embed tag.

Check this code in your browser .
<?php

Download PHP PDF php basic tutorial pdf


echo "Making by umar farooque khan";
switch(rand(1,16))
{
   case 1:
$greet ="1.jpg";
break;
   case 2:
$greet ="2.jpg";
break;
   case 3:
$greet ="3.jpg";
break;
   case 4:
$greet ="4.jpg";
break;
case 5:
$greet ="a(1).jpg";
break;
   case 6:
$greet ="a(2).jpg";
break;
   case 7:
$greet ="a(3).jpg";
break;
   case 8:
$greet ="a(4).jpg";
break;


case 9:
$greet ="a(5).jpg";
break;
   case 10:
$greet ="a(6).jpg";
break;
   case 11:
$greet ="a(7).jpg";
break;
   case 12:
$greet ="a(8).jpg";
break;


case 13:
$greet ="a(9).jpg";
break;
   case 14:
$greet ="a(10).jpg";
break;
   case 15:
$greet ="a(11).jpg";
break;
   case 16:
$greet ="a(12).jpg";
break;

}
echo"<img src='$greet' height='900px' width='1200px'>";
?>



For more on php visit php-tutorial

Thursday, 1 August 2013

Upload File Using Php

Making Upload File Script Using Php html and java script with validation


<pre><!DOCTYPE html>
<head>
</head>
<body></pre>  //use pre tag to not show these tags in server
<center>
< form action = " upload.php" method = " post " enctype = " multipart / form-data " 
name = " upload  " >
  < table width =" 200 " border = " 2 " cellspacing = " 2 " cellpadding = " 2 " >
    < tr >
      < td > Upload a file< /td >
      < td > < input name = " file " type = " file "  / > < / td >
    < / tr >
    < tr >
      < td colspan = " 2 " > < center >
          < input name = " sub " type = " submit " value = " upload " />
        < / center >< / td >
    </tr>
  </table>

</form>
</center>
</body>
</html>
<?php
error_reporting(0);
if(isset($_POST['sub'])) 
     { 
      $name=$_FILES['file']['name'];
 $type=$_FILES['file']['type'];
 $size=$_FILES['file']['size'];
 $tmp=$_FILES['file']['tmp_name'];
        
if($name=='')
{
echo"<script>alert('upload file')</script>";
exit();
}

if(( $type == "image/jpeg" )||($type=="image/gif")||($type=="image/png"))
{
if($size<=500000)
{
if (file_exists("upload file" . $_FILES["file"]["name"]))
 {
 echo $_FILES["file"]["name"] . " already exists. ";
 exit();
 }
 move_uploaded_file($tmp,"$name");
                      echo"<center> <font color='pink' ><h2>successfully uploaded</h2></font><br>".""."<img src=$name> </center>";   
   }
 
 else
 {
 echo"more size";
 }
 
}   
 else
 {
 echo"type not support";
 } 
 
 
 
 
 }

?>

For more php tutorial PHP-tutorial
Output

upload