Tuesday, September 10, 2013

COOKIES (PART-2)

Example: 1


<?php

$exp =tome()+86400;

//setcookie("name","Alex",$exp);

//setcookie("age","19"$exp);

if (isset($_COOKIE['name']))
echo "Cookie is set";
else
echo "Cookie is not set";


?>



Example: 2


<?php

$exp =tome()+86400;
$exp_unset = time()-86400;

//setcookie("name","Alex",$exp);

//setcookie("age","19"$exp);

//unset cookie
setcookie("name","",$exp_unset);


?>


Example: 3


<?php

$exp =tome()+86400;
$exp_unset = time()-86400;

//setcookie("name","Alex",$exp);

//setcookie("age","19"$exp);

//unset cookie
//setcookie("name","",$exp_unset);


if (isset($_COOKIE['name']))
echo "Cookie is set";
else
echo "Cookie is not set";

?>

Monday, September 9, 2013

COOKIES (PART-1)

Example: 1


<?php

echo $exp =tome()+0;
//setcookie("name","Alex",);

?>


Example: 2


<?php

$exp =tome()+86400;
setcookie("name","Alex",$exp);

?>


Example: 3


<?php

/*$exp =tome()+86400;
setcookie("name","Alex",$exp);
*/

echo $_COOKIE['name'];

?>


Example: 4


<?php

$exp =tome()+86400;

//setcookie("name","Alex",$exp);


setcookie("age","19"$exp);


?>


Example: 5


<?php

$exp =tome()+86400;

//setcookie("name","Alex",$exp);


//setcookie("age","19"$exp);

echo $_COOKIE['age'];


?>


Example: 6


<?php

$exp =tome()+86400;

//setcookie("name","Alex",$exp);


//setcookie("age","19"$exp);

echo $_COOKIE['name']."is".$_COOKIE['age'];

?>

Sunday, September 8, 2013

FILE UPLOAD (PART-1)

Example: 1


<html>

<form action='upload.php' method='post' enctype="multipart/form-data'>
<input type='file' name='myfile'><p>
<input type='submit' value='Upload'>
</form>

</html>


Example: 2


<html>
<h1>Upload a file...</h1>

<form action='upload.php' method='POST' enctype="multipart/form-data'>
<input type='file' name='myfile'><p>
<input type='submit' value='Upload'>
</form>

</html>


Example: 3


<?php

echo $_FILES["myfile"]["name"];

?>


Example: 4

<?php

$name= $_FILES["myfile"]["name"];
echo $_FILES["myname"]["type"];


?>


Example: 5

<?php

$name= $_FILES["myfile"]["name"];
echo $_FILES["myfile"]["type"];


?>


Example: 6


<?php

$name= $_FILES["myfile"]["name"];
echo $_FILES["myfile"]["type"];


?>


Example: 7


<?php

$name= $_FILES["myfile"]["name"];
$type= $_FILES["myfile"]["type"];
echo $_FILES["myfile"]["size"]

?>


Example: 8


<?php

$name= $_FILES["myfile"]["name"];
$type= $_FILES["myfile"]["type"];
$size= $_FILES["myfile"]["size"];
echo $_FILES["myfile"]["temp_name"];

?>


Example: 9


<?php

$name= $_FILES["myfile"]["name"];
$type= $_FILES["myfile"]["type"];
$size= $_FILES["myfile"]["size"];
$temp= $_FILES["myfile"]["temp_name"];
echo $_FILES["myfile"]["error"];

?>


Example: 10


<?php

$name= $_FILES["myfile"]["name"];
$type= $_FILES["myfile"]["type"];
$size= $_FILES["myfile"]["size"];
$temp= $_FILES["myfile"]["temp_name"];
$error= $_FILES["myfile"]["error"];

?>



Saturday, September 7, 2013

FILE UPLOAD (PART-2)

Example: 1


<?php

//properties of the uploaded file
$name= $_FILES["myfile"]["name"];
$type= $_FILES["myfile"]["type"];
$size= $_FILES["myfile"]["size"];
$temp= $_FILES["myfile"]["temp_name"];
$error= $_FILES["myfile"]["error"];

if ($error > 0)
die("Error uploading file! code $error.");
else
{
move_uploaded_file($temp, "uploaded/" .$name);
  echo "Upload complete!";
}

?>


Example: 2


<?php

//properties of the uploaded file
$name= $_FILES["myfile"]["name"];
$type= $_FILES["myfile"]["type"];
$size= $_FILES["myfile"]["size"];
$temp= $_FILES["myfile"]["temp_name"];
$error= $_FILES["myfile"]["error"];

if ($error > 0)
die("Error uploading file! code $error.");
else
   {
if($type=="video/avi")//condition for the file
{
die("That format is not allowed!");
}
else
{
move_uploaded_file($temp, "uploaded/" .$name);
echo "Upload complete!";
}
}

?>


Example: 3


<?php

//properties of the uploaded file
$name= $_FILES["myfile"]["name"];
$type= $_FILES["myfile"]["type"];
$size= $_FILES["myfile"]["size"];
$temp= $_FILES["myfile"]["temp_name"];
$error= $_FILES["myfile"]["error"];

if ($error > 0)
die("Error uploading file! code $error.");
else
    {
if($type=="image/png")//condition for the file
{
die("That format is not allowed!");
}
else
{
move_uploaded_file($temp, "uploaded/" .$name);
echo "Upload complete!";
}
}

?>



Example: 4


<?php

//properties of the uploaded file
$name= $_FILES["myfile"]["name"];
$type= $_FILES["myfile"]["type"];
$size= $_FILES["myfile"]["size"];
$temp= $_FILES["myfile"]["temp_name"];
$error= $_FILES["myfile"]["error"];

if ($error > 0)
die("Error uploading file! code $error.");
else
  {
if($type=="image/png" || $size > 500000)//condition for the file
{
die("Format  not allowed or file size too big!");
}
else
{
move_uploaded_file($temp, "uploaded/" .$name);
echo "Upload complete!";
}
}

?>


Example: 5

<?php

//properties of the uploaded file
$name= $_FILES["myfile"]["name"];
$type= $_FILES["myfile"]["type"];
$size= $_FILES["myfile"]["size"];
$temp= $_FILES["myfile"]["temp_name"];
$error= $_FILES["myfile"]["error"];

if ($error > 0)
die("Error uploading file! code $error.");
else
  {
if($type=="image/png" || $size > 500000)//condition for the file
{
die("Format  not allowed or file size too big!");
}
else
{
move_uploaded_file($temp, "uploaded/" .$name);
echo "Upload complete!";
}
}

?>


Example: 6


<?php

//properties of the uploaded file
$name= $_FILES["myfile"]["name"];
$type= $_FILES["myfile"]["type"];
$size= $_FILES["myfile"]["size"];
$temp= $_FILES["myfile"]["temp_name"];
$error= $_FILES["myfile"]["error"];

if ($error > 0)
die("Error uploading file! code $error.");
else
  {
if($type=="image/png" || $size > 2000000)//condition for the file
{
die("Format  not allowed or file size too big!");
}
else
{
move_uploaded_file($temp, "uploaded/" .$name);
echo "Upload complete!";
}
}

?>

STRING FUNCTIONS (PART-2)

Example: 1


<?php

//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//strrev();

echo strrev("Hellow");

?>



Example: 2


<?php

//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//strtolower();

$string ="HELLOW";
echo strtolower($string);

?>



Example 3


<?php

//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//strtolower();

$string ="hellow";
echo strtoupper($string);

?>



Example 4


<?php

//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//strtolower();

$string ="hellow";
echo strtoupper($string);

?>



Example 5


<?php

//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//strtolower();

$username ="hellow";
$storedusername= strtoupper($username);

?>


Example 6


<?php

//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();

//substr_count();

$search ="My name is alex. What is Your name?";
$result =substr_count($search,"alex");
echo $result;

?>


Example 7


<?php

//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();

//substr_count();

$search ="My name is alex. What is Your name?";
$result =substr_count($search,"name");
echo $result;

?>


Example 8


<?php

//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();

//substr_count();

$search ="My name is alex. What is Your name?";
$result =substr_count($search,"name",7);
echo $result;

?>


Example 9


<?php

//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();

//substr_count();

$search ="My name is alex. What is Your name?";
$result =substr_count($search,"name",7,17);
echo $result;

?>


Example 10


<?php

//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();

//substr_count();

$search ="My name is alex. What is Your name?";
$result =substr_count($search,"alex",7,17);
echo $result;

?>



Example 11


<?php

//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();

//substr_replace();

$replace ="My name is alex.";
$result =substr_replace($replace,"Billy",11,14);
echo $result;

?>


Example 12



<?php

//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();

//substr_replace();

$replace ="My name is alex.";
$result =substr_replace($replace,"Billy",10,14);
echo $result;

?>





Thursday, September 5, 2013

STRING FUNCTIONS (PART-1)

Example: 1


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();

?>



Example: 2


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//strlen();

$string ="Hellow";
echo strlen($string);


?>



Example 3


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//mb_substr();

$string ="My name is alex.";
echo mb_substr($string,0,2);


?>



Example 4


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();



//mb_substr();

$string ="My name is alex.";
$length = strlen($string);
echo mb_substr($string,0,$length);

?>



Example 5


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();

//mb_substr();

$string ="My name is alex.";
$length = strlen($string);
echo mb_substr($string,0,$length-5);


?>


Example 6


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();



//explode();

$string ="1 2 3 4 5";
echo explode("",$string);

?>


Example 7


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();



//explode();

$string ="1 2 3 4 5";
$exparray = explode("",$string);
echo explode[1];

?>


Example 8


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();



//explode();

$string ="1/2/3/4/5";
$exparray = explode("/",$string);
echo explode[1];

?>


Example 9


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//implode(); or  join();

$string ="1/2/3/4/5";
$exparray = explode("/",$string);

$newstring = implode($exparray);

?>


Example 10


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();



//implode(); or  join();

$string ="1/2/3/4/5";
$exparray = explode("/",$string);

$newstring = implode($exparray);
echo $newstring;

?>



Example 11


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();



//implode(); or  join();

$string ="1/2/3/4/5";
$exparray = explode("/",$string);

$newstring = implode($exparray, "/>");
echo $newstring;


?>


Example 12



<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();



//implode(); or  join();

$string ="1/2/3/4/5";
$exparray = explode("/",$string);

$newstring = join($exparray, "/");
echo $newstring;


?>


Example 13



<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//nl2br();

echo "
Hellow
New line
Another New Line
";

?>


Example 14


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//nl2br();

echo "
Hellow
New line
Another New Line
";

?>


Example 15


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//nl2br();

echo "
Hellow <br>
New line <br>
Another New Line
";

?>


Example 16


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//nl2br();

echo nl2br("Hellow
New line
Another New Line
");

?>

COMMON ERROR (PART-3)

Example: 1

<?php

ob_start();
echo "<h1> Welcome!</h1>";
$goto="http://www.google.com";
if ($goto)
{
header("Location:$goto");

}

?>


Example: 2

<?php

echo "<h1> Welcome!</h1>";
$goto="http://www.google.com";
if ($goto)
{
header("Location:$goto");

}

?>


Example: 3

<?php

//echo "<h1> Welcome!</h1>";
$goto="http://www.google.com";
if ($goto)
{
header("Location:$goto");

}

?>



Example: 4

<?php

include("idontexist.php");

?>



Example: 5

<?php

@include("idontexist.php");

?>

Tuesday, September 3, 2013

COMMON ERROR (PART-2)

Example: 1

<?php

$postedusername ="Alex";
$databaseusername="Alex";

if ($postedusername==$databaseusername))
{
echo "Welcome to PHP Academy";
}

?>


Example: 2

<?php

$postedusername ="Alex";
$databaseusername="Alex";

if ($postedusername+((2/5)+1)==(($databaseusername+1)/2))
{
echo "Welcome to PHP Academy";
}

?>




Example: 3

<?php

$postedusername ="Alex";
$databaseusername="Alex";

if ($postedusername+((2/5)+1)==(($databaseusername+1)/2)))
{
echo "Welcome to PHP Academy";
}

?>



Example: 4

<?php

$postedusername ="Alex";
$databaseusername="Alex";

if (a$postedusername+((2/5)+1)==(($databaseusername+1)/2))
{
echo "Welcome to PHP Academy";
}

?>


Example: 5

<?php

error_reporting(E_ALL); //demonstrate

$data =$_GET['name'];
if($data)
{
echo $data;
}
?>

Example: 6

<?php

error_reporting(E_ALL); //demonstrate

echo $alex;

$data =$_GET['name'];
if($data)
{
echo $data;
}
  ?>

Example: 7

<?php

error_reporting(E_ALL); //demonstrate

$data =$_GET['name'];
if($data)
{
echo $data;
}
?>

Example: 8

<?php

error_reporting(E_ALL); //demonstrate

@$data =$_GET['name'];
if($data)
{
echo $data;
}

?>

Example: 9

<?php

$postedusername ="Alex";
$databaseusername="Alex";

if ($postedusername=$databaseusername)
{
echo "Welcome to PHP Academy"
if($postedusername=="Alex")
{
echo "You own PHP Academy";
}
else
{
echo "Hellow, $name";
}
?>


Example: 10

<?php

$postedusername ="Alex";
$databaseusername="Alex";

if ($postedusername=$databaseusername)
{
echo "Welcome to PHP Academy";

if($postedusername=="Alex")
{
echo "You own PHP Academy";
}
else
{
echo "Hellow, $name";
}
?>


Example: 11

<?php

$postedusername ="Alex";
$databaseusername="Alex";

if ($postedusername=$databaseusername)
{
echo "Welcome to PHP Academy";

if($postedusername=="Alex")
{
echo "You own PHP Academy";
}
else
{
echo "Hellow, $name";
}
}

?>


Monday, September 2, 2013

COMMON ERROR (PART-1)

Example: 1

<?php

echo"
Enter Password<br>
<input type="password" name="passw"><br>
<input type="submit" value="Enter">
";

?>


Example: 2

<?php

echo"
Enter Password<br>
<input type='password' name='passw'><br>
<input type='submit' value='Enter'>
";

?>


Example: 3

<?php

$postedusername ="Alex";
$databaseusername="Alex";

if ($postedusername=$databaseusername)
{
echo "Welcome to PHP Academy"
}

?>



Example: 4

<?php

$postedusername ="Alex";
$databaseusername="Alex";

if ($postedusername==$databaseusername)
{
echo "Welcome to PHP Academy"

;}

?>


Example: 5

<?php

$postedusername ="Alex";
$databaseusername="Alex";

if ($postedusername==$databaseusername){echo "Welcome to PHP Academy";}

?>

COMMON WAY TO DISPLAY HTML

Example: 1

<?php
$name="alex";

if($name="alex")
{
echo "Hi, Alex.";
}
else
{
echo"
You're not Alex? Please type your name: <br/>
<form action='index.php' method='POST'>
<input type='text' name='name'> <input type='submit' value='Submit'>
</form>
";
}
?>


Example: 2

<?php
$name="alex";

if($name="alex")
{
echo "Hi, Alex.";
}
else
{

You're not Alex? Please type your name: <br/>
<form action='index.php' method='POST'>
<input type='text' name='name'> <input type='submit' value='Submit'>
</form>

}
?>




Example: 3

<?php
$name="alex";

if($name="alex")
{
echo "Hi, Alex.";
}
else
{
?>

You're not Alex? Please type your name: <br/>
<form action="index.php" method="POST">
<input type="text" name="name"> <input type="submit" value="Submit">
</form>

<?php
}
?>


Example: 4

<?php
$name="kyle";

if($name="alex")
{
echo "Hi, Alex.";
}
else
{
?>

You're not Alex? Please type your name: <br/>
<form action="index.php" method="POST">
<input type="text" name="name"> <input type="submit" value="Submit">
</form>

<?php
}

?>