Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- echo "My first PHP script!";
- echo "<br>";
- $x = 5+5;
- echo $x;
- echo "<br>";
- //--------------------------------------------------------
- echo gettype($x); //return datatype
- echo "<br>";
- $color="red";
- echo "Color is ".$color."<br>";
- define("Name", "Lovely Professional University"); //constant
- echo Name;
- echo "<br>";
- printf("Regno is %d",11604722);
- echo "<br>";
- var_dump($x); //return datatype and value
- echo "<br>";
- //-----------------------------------------------------------
- $cars = array("Audi","BMW","Toyota"); //array
- echo "First Car is ".$cars[0]."<br>";
- var_dump($cars);
- echo "<br>";
- //-----------------------------------------------------------------------
- echo strlen("Hello World!"); //returns the length of a string
- echo "<br>";
- echo str_word_count("Hello World!"); //counts the number of words in a string
- echo "<br>";
- echo strrev("Hello World!"); //reverses a string
- echo "<br>";
- echo strpos("Hello World!", "World"); //searches for a specific text within a string
- echo "<br>";
- echo str_replace("World", "India", "Hello World!"); //replaces some characters with some other characters in a string
- echo "<br>";
- $temp="Smoking is good for Health";
- echo str_replace("good", "bad", $temp,$count)."<br>";
- echo $count."<br>";
- //-------------------------------------------------------------------------------------------------------------------
- $a=10;
- $b=10;
- var_dump($a==$b); //Equal
- echo "<br>";
- var_dump($a===$b); //Identical
- echo "<br>";
- var_dump($a!=$b); //Not equal
- echo "<br>";
- var_dump($a<>$b); //Not equal
- echo "<br>";
- var_dump($a!==$b); //Not identical
- echo "<br>";
- var_dump($a>$b); //Greater than
- echo "<br>";
- var_dump($a<$b); //Less than
- echo "<br>";
- var_dump($a>=$b); //Greater than or equal to
- echo "<br>";
- var_dump($a<=$b); //Less than or equal to
- echo "<br>";
- //----------------------------------------------------------
- echo $a++."<br>"; //Pre-increment
- echo ++$a."<br>"; //Post-increment
- echo $b--."<br>"; //Pre-decrement
- echo --$b."<br>"; //Post-decrement
- $a=20; // decision making
- if($a==2)
- {
- echo "Hello World"."<br>";
- }
- elseif ($a=="20")
- {
- echo "This is string value";
- }
- else
- {
- echo "Hello Class";
- }
- //-------------------------------------------------------------
- $year=2016;
- if($year%4==0 && ($year%100!=0 || $year%400!=0))
- {
- echo "<br>"."Leap Year";
- }
- else
- {
- echo "Not a Leap Year";
- }
- //------------------------------------------------------------------
- $var=12345;
- if ($var%3==0)
- {
- echo "<br>"."Divisible by 3";
- }
- if ($var%5==0)
- {
- echo "<br>"."Divisible by 5";
- }
- if ($var%3==0 && $var%5==0)
- {
- echo "<br>"."Divisible by 3 and 5";
- }
- else
- {
- echo "<br>"."Not Divisible by 3 or 5";
- }
- //-------------------------------------------------------------------------------------
- echo "<br>".date("d"); //The day of the month (from 01 to 31)
- echo "<br>".date("D"); //A textual representation of a day (three letters)
- echo "<br>".date("H"); //24-hour format of an hour (00 to 23)
- echo "<br>".date("A"); //Uppercase AM or PM
- echo "<br>".date("L"); //Whether it's a leap year (1 if it is a leap year, 0 otherwise)
- echo "<br>".date("Y-m-d"); //Year date month
- //----------------------------------------------------------------------
- $a=10;
- $b=5;
- $c="/";
- switch($c)
- {
- case "+": echo $a+$b;
- break;
- case "-": echo $a-$b;
- break;
- }
- //--------------------------------------------------------------------
- $start = 1;
- $end = 10;
- $sum = 0;
- for ($i = $start; $i <= $end; $i++) {
- $sum += $i;
- }
- echo "<br>"."Sum from " . $start . " to " . $end . " = " . $sum;
- //---------------------------------------------------------------------
- $arr=array("Abc",10,20);
- echo "<br>";
- print_r($arr);
- echo "<br>".count($arr);
- echo "<br>".$arr[0]."<br>";
- var_dump($arr);
- for($i=0;$i<3;$i++)
- {
- echo "<br>".$arr[$i];
- }
- foreach($arr as $x => $x_value) {
- echo "<br>"."Key=" . $x . ", Value=" . $x_value;
- }
- //------------------------------------
- $arr["name"]="DP";
- echo "<br>".$arr["name"];
- //--------------------------------------
- $numbers = array(4, 6, 2, 22, 11);
- $numbers[0]=1;
- $numbers[5]=9;
- echo $numbers[0];
- echo $numbers[5];
- sort($numbers);
- $arrlength = count($numbers);
- echo "<br>";
- for($x = 0; $x < $arrlength; $x++)
- {
- echo $numbers[$x];
- echo "<br>";
- }
- //----------------------------------------------------------------------------
- $cars = array //TWO DIMENSIONAL ARRAY
- (
- array("Volvo",22,18),
- array("BMW",15,13),
- array("Audi",5,2),
- array("Land Rover",17,15)
- );
- echo "<br>".$cars[0][0].": In stock: ".$cars[0][1].", sold: ".$cars[0][2];
- echo "<br>".$cars[1][0].": In stock: ".$cars[1][1].", sold: ".$cars[1][2];
- echo "<br>".$cars[2][0].": In stock: ".$cars[2][1].", sold: ".$cars[2][2];
- echo "<br>".$cars[3][0].": In stock: ".$cars[3][1].", sold: ".$cars[3][2];
- for($i=0;$i<3;$i++)
- {
- echo "<br>";
- for($j=0;$j<3;$j++)
- {
- echo $cars[$i][$j];
- }
- }
- //---------------------------------------------------------------------------
- $marks = array(
- "mohammad" => array (
- "physics" => 35,
- "maths" => 30,
- "chemistry" => 39
- ),
- "qadir" => array (
- "physics" => 30,
- "maths" => 32,
- "chemistry" => 29
- ),
- "zara" => array (
- "physics" => 31,
- "maths" => 22,
- "chemistry" => 39
- )
- );
- /* Accessing multi-dimensional array values */
- echo "<br>"."Marks for mohammad in physics : " ;
- echo $marks['mohammad']['physics'] . "<br />";
- echo "Marks for qadir in maths : ";
- echo $marks['qadir']['maths'] . "<br />";
- echo "Marks for zara in chemistry : " ;
- echo $marks['zara']['chemistry'] . "<br />";
- //----------------------------------------------------------------------------------
- $cars = array("Volvo", "BMW", "Toyota");
- sort($cars);
- //--------------------------------------------------------------------------------
- $arr1=array("abc","def");
- $arr2=array("ghi","jkl");
- print_r(array_merge($arr1,$arr2)); //merging two arrays
- echo "<br>";
- $union=$arr1+$arr2;
- //var_dump($union); //Union
- echo "<br>";
- print_r($union);
- echo "<br>";
- $my_array1 = array("size" => "big", 2,3 ); //Associative Array Union and Merge
- $my_array2 = array("a", "b", "size" => "medium",
- "shape" => "circle", 4);
- print_r(array_merge($my_array1, $my_array2));
- echo "<br>";
- $union2=$my_array1+$my_array2;
- print_r($union2);
- //------------------------------------------------------------------------------
- //Array Slice
- echo "<br>";
- $a=array("red","green","blue","yellow","brown");
- print_r(array_slice($a,2,3));
- //------------------------------------------------------------------------------
- echo "<br>";
- $str = "Hello world. It's a beautiful day."; //Converting String to Array
- print_r (explode(" ",$str));
- //------------------------------------------------------------------------------
- echo "<br>";
- $arr = array('Hello','World!','Beautiful','Day!');//Converting Array to String
- echo implode(" & ",$arr);//here " " is delimiter
- //-----------------------------------------------------------------------------
- echo "<br>";
- $a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
- $result=array_flip($a1); //Swapping Array Keys and Value
- print_r($result);
- //----------------------------------------------------------------------------
- echo "<br>";
- $a=array("a"=>"red","b"=>"green","c"=>"red");
- print_r(array_unique($a));//Removind Duplicacy in array elements
- //echo join(" ,",$a);
- //------------------------------------------------------------------------------------------
- //WAPS to calculate and display 5 lowest and highest temperatures?
- echo "<br>";
- $temp=array(78,60,62,68,71,68,73,85,66,64,76,63,75,76,73,68,62,73,72,65,74,62,62,65,64,68,73,75,79,73);
- $temp1=array_unique($temp);
- sort($temp1);
- echo "List of 5 lowest temperatures are ";
- print_r(array_slice($temp1,0,5));
- $temp2=array_reverse($temp1);
- echo "<br>";
- echo "List of 5 highest temperatures are ";
- print_r(array_slice($temp2,0,5));
- echo "<br>";
- //----------------------------------------------------------------------------------------------------
- function fun($b) //Function
- {
- echo $b;
- }
- $a=10;
- fun($a);
- //--------------------------------------------------------------------------------------------------
- function fun1($a,$b)
- {
- $c=$a+$b;
- return $c;
- }
- echo "<br>Sum is ".fun1(5,10);
- //---------------------------------------
- echo "<br>";
- function fun2($dividend,$divisor)
- {
- $quotient=$dividend/$divisor;
- $array=array($dividend,$divisor,$quotient);
- return $array;
- }
- print_r(fun2(10,20));
- //-------------------------------------------------------------------------
- function factorial($number) //Factorial of a number using recursion
- {
- if ($number < 2)
- {
- return 1;
- }
- return ($number * factorial($number-1));
- }
- echo "<br>Factorial is ".factorial(5);
- function factorial1($num)
- {
- $fact=1;
- for($i=$num;$i<0;$i--)
- {
- $fact=$fact*$i;
- }
- return $fact;
- }
- echo factorial1(20);
- //------------------------------------------------------------------
- function fun3(&$a,&$b)
- {
- $c=$a+$b;
- return $c;
- }
- $x=10;
- $y=20;
- echo "<br>Sum is ".fun3($x,$y);
- //-----------------------------------
- function setHeight($minheight=50)
- {
- echo "<br>The height is : $minheight <br>";
- }
- setHeight(350);
- setHeight();
- setHeight(135);
- setHeight(80);
- //------------------------------------------------------------
- function sayHello()
- {
- echo "hello"."<br>";
- }
- $function_holder="sayhello";
- $function_holder();
- //--------------------------------------------------------------
- echo "<br>";
- function add(...$numbers)
- {
- $sum=0;
- foreach($numbers as $n)
- {
- $sum +=$n;
- }
- return $sum;
- }
- echo add(1,2,3,4);
- //--------------------------------------------------------
- echo "<br>";
- function even(...$numbers)
- {
- $sum=0;
- foreach($numbers as $n)
- {
- if($n%2==0)
- {
- $sum +=$n;
- }
- }
- return $sum;
- }
- echo even(1,2,3,4);
- //--------------------------------------------------------
- echo "<br>"; //Local,Global,Static Variables
- $a=20;
- $x=10;
- function ex()
- {
- $x=5;
- global $a;
- static $s=30;
- $a++;
- $s++;
- $x++;
- echo "<br>Global Variable ".$a;
- echo "<br>Local Variable ".$x;
- echo "<br>Static Variable ".$s."<br>";
- }
- ex();
- ex();
- ex();
- ex();
- echo $x;
- // echo $s will give error because scope of static variable is inside the block only.
- //--------------------------------------------------------------------------------------
- <?php
- print_r($_GET)
- if(isset($_GET['name'],$_GET['Rollo'],$_GET['Age'],$_GET['Address']))
- ?>
- -----------------------------------------------cookie-----------
- <?php
- $cookie_name="user";
- $cookie_value="Juju Spices";
- setcookie($cookie_name, $cookie_value, time() + (86400*30), "/");
- ?>
- <html>
- <body>
- <?php
- if(!isset($_COOKIE[$cookie_name]))
- {
- echo "Cookie named " . $cookie_name . " is not set!";
- }
- else
- {
- echo "Cookie " . $cookie_name . " is set!<br>";
- echo "Value is: " . $_COOKIE[$cookie_name];
- }
- ?>
- </body>
- </html>
- ------------------------------------session-------------------
- <?php
- session_start();
- ?>
- <!DOCTYPE html>
- <html>
- <body>
- <?php
- $_SESSION["favcolor"] = "green";
- $_SESSION["favanimal"] = "cat";
- echo "Session variables are set.";
- ?>
- </body>
- </html>
- ----------------------------------------------------------------------------------
- <?php
- session_start();
- ?>
- <!DOCTYPE html>
- <html>
- <body>
- <?php
- // Echo session variables that were set on previous page
- echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>";
- echo "Favorite animal is " . $_SESSION["favanimal"] . ".";
- ?>
- </body>
- </html>
- ------------------------------------------------------------------------------------------
- <?php
- session_start();
- ?>
- <!DOCTYPE html>
- <html>
- <body>
- <?php
- print_r($_SESSION);
- ?>
- </body>
- </html>
- ---------------------------------------Sanitization------------------------------
- <?php
- print_r(filter_list());
- if(isset($_POST['submit']));
- $a= $_POST['name'];
- if(empty($a))
- {
- echo "Name Not found";
- }
- else
- {
- $a=filter_var($a,FILTER_SANITIZE_STRING);
- echo "<br>";
- echo $a."==is Sanitized.<br>";
- if(!preg_match("/^[a-zA-Z]+$/",$a))
- {
- echo "Name Invalid<br>";
- }
- else
- {
- echo "Valid Named<br>";
- }
- }
- $b=$_POST['Roll'];
- $c=$_POST['Age'];
- $d=$_POST['Address'];
- echo "Name is {$a},Roll is {$b},Age is {$c},Address is {$d}";
- ?>
- <form action="get.php" method="POST">
- <input type="text" name="name" placeholder="Name" required="name">
- <input type="text" name="Roll" placeholder="roll">
- <input type="text" name="Age" placeholder="age">
- <input type="text" name="Address" placeholder="add">
- <input type="Submit">
- </form>
- ----------------------------------------------------------------form validation---------------------
- <?php
- $a=$_GET["name"];
- if(empty($a))
- {
- echo 'name not found';
- }
- else
- {
- if(!preg_match("/^[a-zA-Z]*$/",$a))
- {
- echo "only letters are allowed<br>";
- }
- else
- {
- echo $a."<br>";
- }
- }
- $b=$_GET["email"];
- if(empty($b))
- {
- echo 'email not found<br>';
- }
- else
- {
- if(!filter_var($b,FILTER_VALIDATE_EMAIL))
- {
- echo "invalid email<br>";
- }
- else
- {
- echo $b."<br>";
- }
- }
- $c=$_GET["number"];
- if(empty($c))
- {
- echo 'number not found<br>';
- }
- else
- {
- if(!preg_match("/^[0-9]{10}+$/",$c))
- {
- echo "only numbers are allowed<br>";
- }
- else
- {
- echo $c;
- }
- }
- ?>
- ------------------------------------------------------database query------------------------
- <?php
- $username ="root";
- $password = "";
- $hostname ="localhost";;
- //connetion to the database
- $dbhandle =mysql_connect($hostname, $username, $password)
- or die("Unable to connect to mySql");
- echo"Connected to MySQL<br>";
- // select a database to work with
- $selected = mysql_select_db("examples",$dbhandle)
- or die("Could not select examples");
- //execute the SQL query and return records
- $result = mysql_query("SELECT id, model, year FROM cars");
- //fetch the data from the database
- while($row =mysql_fetch_array($result))
- {
- echo "ID:".$row{'id'}."Name:".$row{'model'}."year:".$row{'year'}."<br>";
- }
- //close the connection
- mysql_close($dbhandle);
- ?>
- ---------------------------------------------------------------create database------------
- <?php
- $hostname = "localhost";
- $username = "root";
- $password = "";
- // Create connection
- $conn = new mysqli($hostname, $username, $password);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- // Create database
- $sql = "CREATE DATABASE myDB1";
- if ($conn->query($sql)== TRUE) {
- echo "Database created successfully";
- } else {
- echo "Error creating database: " . $conn->error;
- }
- $conn->close();
- ?>
- -------------------------create table--------------------
- sql to create table
- $sql = "CREATE TABLE employee (
- emp_id INT(1) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
- emp_name VARCHAR(30) NOT NULL,
- emp_dept VARCHAR(30) NOT NULL,
- salary INT(6)
- )";
- -----------------------------------data insert
- <?php
- $hostname = "localhost";
- $username = "root";
- $password = "";
- $dbname = "mydb";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "INSERT INTO employee (emp_id,emp_name,emp_dept,salary)
- VALUES (1,'a','CSE',40000);";
- $sql = "INSERT INTO employee (emp_id,emp_name,emp_dept,salary)
- VALUES (2,'b','IT',30000);";
- $sql = "INSERT INTO employee (emp_id,emp_name,emp_dept,salary)
- VALUES (3,'c','EEE',45000);";
- $sql = "INSERT INTO employee (emp_id,emp_name,emp_dept,salary)
- VALUES (4,'d','ECE',50000);";
- $sql = "INSERT INTO employee (emp_id,emp_name,emp_dept,salary)
- VALUES (5,'e','CSE',55000);";
- if ($conn->multi_query($sql) === TRUE) {
- echo "New records created successfully";
- } else {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- $conn->close();
- ?>
- ----------------------------------------------------post method-----------
- <?php
- if(isset($_POST["Submit"]))
- {
- extract($_POST);
- $a= $_POST["name"];
- $b=$_POST['roll'];
- $c=$_POST['class'];
- if(empty($name)){
- echo "value is NOT there";
- }
- else
- {
- echo $a;
- }
- }
- ?>
- <form action="post.php" method="post">
- name<input type="text" name="name" placeholder="">
- rollo<input type="text" name="roll" placeholder="">
- class<input type="text" name="class" placeholder="">
- <input type="Submit">
- </form>
- ------------------------------------db.php-----------
- <?php
- $g=mysqli_connect('localhost','root','','hd1');
- if($g==false)
- {
- echo "connection is not done";
- }
- else
- {
- echo "connection is done";
- }
- if(isset($_POST["submit"]))
- {
- extract($_POST);
- $a=$_POST["first_name"];
- $b=$_POST['last_name'];
- $c=$_POST['reg_no'];
- $d=$_POST['password'];
- $sql="INSERT INTO mytable(first_name,last_name,reg_no,password) VALUES ('$a', '$b', '$c','$d')";
- if(mysqli_query($g,$sql))
- {
- echo "data insert";
- }
- else{
- echo "data not insert";
- }
- }
- ?>
- <form action="db.php" method="post"><br>
- first_name<input type="text" name="first_name" placeholder=""><br>
- last_name<input type="text" name="last_name" placeholder=""><br>
- reg_no<input type="text" name="reg_no" placeholder=""><br>
- password<input type="password" name="password" placeholder=""><br>
- <input type="submit" name="submit">
- ---------------------------------------------------------login.php-----------
- <?php
- $connect=mysqli_connect("localhost","root","" ,"hd1");
- if($connect->connect_error)
- {
- die("connection failed:" . $connect->connect_error);
- }
- echo "Connnection success";
- if(isset($_POST['login'])){
- $first_name=$_POST['first_name'];
- $password=$_POST['password'];
- $query="select * from mytable where first_name='$first_name' and password='$password'";
- $result=mysqli_query($connect,$query);
- if(mysqli_num_rows($result)>0)
- {
- echo "Login ";
- }
- else
- {
- echo "<script>alert('error login')</script>";
- }
- }
- ?>
- <form method="POST" action="login.php">
- <input type="text" name="first_name" placeholder="first_name" required/>
- <input type="password" name="password" placeholder="password" required/>
- <button name="login" type="submit">Login</button>
- </form>
- -----------------------------------------------email sent----------
- <?php
- include('C:/xamppp/htdocs/phpclass/PHPMailerAutoload.php');
- include('C:/xamppp/htdocs/phpclass/class.smtp.php');
- $mail= new PHPMailer();
- $mail->isSMTP();
- $mail->SMTPAuth= true;
- $mail->SMTPSecure='t1s'; //transport layer security protocol
- $mail->Host = 'smtp.gmail.com';
- $mail->Port = 587;
- $mail->Username= 'sharmashikha0698@gmail.com';
- $mail->Password = '';
- $mail->Subject = 'hello';
- $mail->Body = 'mail';
- $mail->addAddress('sharmashikha0698@gmail.com');
- $mail->Send();
- if(!$mail->Send())
- {
- echo "message not sent";
- }
- else
- {
- echo "message sent";
- }
- ?>
- -------------------------------------overriding---------
- <?php
- // The parent class has hello method that returns "beep".
- class Car {
- public function hello()
- {
- echo "beep";
- }
- }
- //The child class has hello method that returns "Halllo"
- class SportsCar extends Car {
- public function hello()
- {
- echo "Hallo";
- parent::hello();
- }
- }
- //Create a new object
- $sportsCar1=new SportsCar();
- //Get the result of the hello method
- echo $sportsCar1 -> hello();
- ?>
- -----------------------------session login------
- <?php
- session_start();
- $message="";
- if(count($_POST)>0) {
- $con = mysqli_connect('127.0.0.1:3306','root','','admin') or die('Unable To connect');
- $result = mysqli_query($con,"SELECT * FROM login_user WHERE name='" . $_POST["name"] . "' and password = '". $_POST["password"]."'");
- $row = mysqli_fetch_array($result);
- if(is_array($row)) {
- $_SESSION["id"] = $row[id];
- $_SESSION["name"] = $row[name];
- } else {
- $message = "Invalid Username or Password!";
- }
- }
- if(isset($_SESSION["id"])) {
- header("Location:index.php");
- }
- ?>
- <html>
- <head>
- <title>User Login</title>
- </head>
- <body>
- <form name="frmUser" method="post" action="" align="center">
- <div class="message"><?php if($message!="") { echo $message; } ?></div>
- <h3 align="center">Enter Login Details</h3>
- Username:<br>
- <input type="text" name="name">
- <br>
- Password:<br>
- <input type="password" name="password">
- <br><br>
- <input type="submit" name="submit" value="Submit">
- <input type="reset">
- </form>
- </body>
- </html>
- -----------------------------------session index
- <?php
- session_start();
- ?>
- <html>
- <head>
- <title>User Login</title>
- </head>
- <body>
- <?php
- if($_SESSION["name"]) {
- ?>
- Welcome <?php echo $_SESSION["name"]; ?>. Click here to <a href="logout.php" tite="Logout">Logout.
- <?php
- }else echo "<h1>Please login first .</h1>";
- ?>
- </body>
- </html>
- ---------------------------session logout-----------
- <?php
- session_start();
- unset($_SESSION["id"]);
- unset($_SESSION["name"]);
- header("Location:login.php");
- ?>
- ---------------------------------------------------cookie login
- <?php
- session_start();
- if(isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
- if($_COOKIE['username']=='abc' && $_COOKIE['password']=='123') {
- $_SESSION['username'] = $_COOKIE['username'];
- header('location:welcome.php');
- }
- else
- $error = "Account's Invalid";
- }
- if(isset($_POST['login'])){
- if($_POST['username']=='abc' && $_POST['password']=='123'){
- $_SESSION['username'] = $_POST['username'];
- if($_POST['remember'] != NULL) {
- setcookie('username', $_POST['username'], time() + (86400 * 30), "/");
- setcookie('password', $_POST['password'], time() + (86400 * 30), "/");
- }
- header('location:welcome.php');
- }
- else {
- $error = "Account's Invalid";
- }
- }
- ?>
- <form method="post">
- <fieldset>
- <legend>Login</legend>
- <?php echo isset($error) ? $error : ''; ?>
- <table cellpadding="2" cellspacing="2">
- <tr>
- <td>Username</td>
- <td><input type="text" name="username"></td>
- </tr>
- <tr>
- <td>Password</td>
- <td><input type="password" name="password"></td>
- </tr>
- <tr>
- <td>Remember Me</td>
- <td><input type="checkbox" name="remember"></td>
- </tr>
- <tr>
- <td> </td>
- <td><input type="submit" name="login" value="Login"></td>
- </tr>
- </table>
- </fieldset>
- </form>
- -----------------------------------------------------------------Welcome Page
- <?php
- session_start();
- if(isset($_GET['action']) && $_GET['action']=='logout'){
- // Remoce session
- unset($_SESSION['username']);
- // Remoce cookie
- setcookie('username', '', 0, "/");
- setcookie('password', '', 0, "/");
- header('location:index.php');
- }
- echo 'Welcome '.$_SESSION['username'];
- ?>
- <br>
- <a href="welcome.php?action=logout">Logout</a>
Add Comment
Please, Sign In to add comment