ad

Wednesday, July 10, 2024

get method php

             


What is the $_GET Method

$_GET is one of the main global variables in PHP. It is a combination of variables that are passed to the current version of the query string appended to the HTTP request URL. Note that this array is populated by each request with the query string appended to the GET request. In this case, the browser uses the HTTP GET method to send the request to the server's URL. The query string appended to the URL can have a key/value pair concatenated with the "&" symbol. The $_GET associative array stores these key/value pairs. If you are using XAMPP server on Windows, put the script as "hello.php" in the "c:/xampp/htdocs" folder.

Example :-

Source Code  :-

<html>
<body>
   <form action="text.php" method="get">
      <p>First Name: <input type="text" name="first"/></p>
      <p>Last Name: <input type="text" name="last" /></p>
      <input type="submit" value="Submit" />
   </form>
</body>
</html>

Output :-



Difference Between GET and POST in PHP 

 

              GET

 

              POST


 

Get method can be bookmarked

 

Post method cannot be bookmarked

 

Get method can be cached

Post method not cached

 

Get method parameters remain in browser history.

 

Post method are not saved in browser history.

Get method only ASCll  characters allowed

 Post method No restrictions Binary data also allowed.

 

Get method data is visible to everyone in the URL

 

Post method Data is not displayed in the URL

Get method has a length limitation of 255 characters.

 

Post method does not have a length limitation

Get method  requests are is more efficient and are used More than a post

 

Post method request is less efficient and used less than get

Get method  limited are the amount  of data can be sent because data is sent in header.

 

Post method  large amount of the  data can be a sent body

Get is less secure compared to Post because data sent is part of the URL

 

 Post is little safer than Get because the  parameters  are not stored is browser history

Related Post:-

php program to print alphabet pattern D

bdi tag in html

PHP $_POST Method

 


What is PHP  for $_POST

One of the common ways to communicate data from a client (such a web browser) to a server via HTTP is through the POST method. It is often used in web development and is specified by the HTTP protocol. This is especially true when interacting with forms and submitting data that must be processed or save. server.$_POST is one of the default variables or superglobal variables in PHP. It is a combination of key/value pairs passed to the URL via the HTTP POST method, using the URLEncoded or multipart/form-data format in the request.

Purpose :-

 Sending data to the server using POST requests is common for creating or updating server resources. For instance, the POST method is typically used to send data to the server when you submit a form on a website (such as to create a new account or leave a remark).

Data Transmission :-

In a POST request, data is transmitted in the HTTP request body as opposed to the GET method, which appends data to the URL. Because of this, it may be used to deliver bigger files or sensitive data that shouldn't be seen through the URL.

Security :- 

Sensitive data is better protected with the POST technique as it is not saved in the URL parameters, server logs, or browser history. It does not, however, encrypt the data by default; for safe transmission, other precautions such as HTTPS need be taken.

Implementation :-

When developing a website with PHP or any other server-side language, you respond to POST requests by gaining access to the client-sent data. For example, in PHP, the $_POST superglobal array contains data supplied via POST.

  Limitation :- 

The POST method is limited by the size of data that can be transferred to the server side. This limit may vary depending on server configuration and PHP settings (post_max_size in php.ini).


Example :-


HTML form  (save index.html):-
  input type  'first_name', 'last_name','address'
'
submits the data process_form.php use POST method ('method=post')

PHP 

 Checks form use POST($_SERVER["REQUEST_METHOD"]=="POST")
 Display submitted data PHP 'echo' statement

When you write the form in index.html and 

     click "Send", the data (first_name, last_name,   address) will be sent to process_form.php using the POST method. We collect information and show it to the user.

Source Code -


<html>
<body>

// html code create a form

   <form action="<?php echo $_SERVER
['PHP_SELF'];?>" method="POST">
      <p>First Name: <input type="text"
name="first_name"/> </p>
      <p>Last Name: <input type="text"
name="last_name" /></p>
      <p>Address : <input type="text"
name="address"></p>
      <input type="submit" value="Submit" />
   </form>

//php code post method
   
<?php
      echo "<h3>First Name: "
. $_POST['first_name'] . "<br /> " .
      "Last Name: " . $_POST['last_name']
."<br>"."Address:".$_POST['address']. "</h3>";
   ?>

</body>
</html>

OutPut :-






Related Post :-

php data type

html block and inline element

javascript do while loop

Tuesday, July 9, 2024

PHP File Handling


What is the File Handling  in php

The term "file handling" refers to a group of procedures in PHP that enable read/write operations on disk files using PHP code. In PHP, a file is a resource object, from which data may be read or written to in a linear way.


 create a file 

" filehandling.txt" , stored the server data.

web desingning free of cost

learn programming language =webdesigningtheory.blogspot.com


    PHP Open file-fopen()

  Example  :-


<?php
      $file = fopen(" filehandling.txt","r");
    ?>

   
OUTPut :-

  web desingning free of cost

learn programming language =webdesigningtheory.blogspot.com


  ஃPHP Close File- fclose() 

PHP fclose() function use close open file pointer.

    Syntax :-

fclose(resource $handle)

Example :-


<?php
fclose($handle);
?>


  ஃ PHP Read File - fread()

PHP fread() function use to read content file. accept two argument.

   Example :-



<?php
   $file = fopen("filehandling.txt","r");
   $content = fread($file,filesize(filehandling.txt"));
   echo $content;
   fclose($file);
   ?>

   

  ஃ PHP  Write File - fwrite()

 Example  :-

 
 <?php
$file = fopen("filehandling.txt","w");
fwrite($file, "This is a test.");
fclose($file);
?>


  ஃ PHP Delete File- unlink()

   Example  :-


<?php
unlink ("data.txt");
echo "file delete";
?>

Related Post :-

php session

html drop down button

PHP Cookies


What is a Cookie 

Cookies are frequently used to help identify users. A cookie is a little file that is embedded on the user's computer by the server. The cookie will be sent each time a browser request is made by the same machine. Cookie values may be created and retrieved using PHP.

Client-side storage is used for PHP cookies. Sessions are more secure than PHP cookies.Please try to use sessions rather than cookies as much as you can.
A PHP cookie is a little data file that is kept on the client browser. It is employed in

acknowledge the person.Cookies are stored in the client browser after being generated on the server. Three steps are involved in the cookie to user info process. The browser receives a collection of cookies from the PHP Server script, such as name, age, address, or phone number, and so forth.This data is stored by the browser locally on the computer for further use.The browser transmits the cookies the next time it makes a request to the web server. information to the server, which then utilizes it to determine 


Create Cookies with PHP

Cookie is created with the setcookie() function.

   Syntax

setcooki(name, value, expire, path, domain, secure, httponly);


1] Name :- set the name of the cookie and is stored in enviroment variable called                        HTTP_COOKIE_VARS. variable  use accessing cookies.

2] Value :- set the value name variable and content store.

3] Expiry :- future  time in second 00:00:00 GMT 7st Jul 2024

       parameter is not set cookie. cookie automatically expire web Browser is closed.

4] Path :- specifies directories which cookie a valid. single forward slash character                permits cookie be valid all direction.

5] Domain :- use to specify the domain name. all cookies only valid host and domain created 

6] Secure :- cookie should only sent secure transmission using HTTPS.  cookie sent by      regular HTTP.

Example :-


<?php
setcookie("user", "geeta");
?>
<html>
    <body>
        <?php
           if(!isset($_COOKIE["user"]))
           {
            echo "cookie not found";
           }
            else{
           echo " cookie :- ".$_COOKIE["user"];
           }
        ?>
</body>
    </html>

Output :- 






2] Retrieve a Cookie

$cookie super global variable .

Example:-

Return cookie value:-

$value=$COOKIE["cookiename"];


 3]Delete a Cookie

delete or remove cookie. expire the cookie. 

Example :-

 
<?php
setcookie("cookiename", "", time()-3600);
?>


Related Post :-


html heading tag

php program print diamond number pattern

php program using sum of digits

PHP Data and Time Function

            

   PHP Data and  Time

The  dete() function accept a format string as parameter 
formate the local date and time specified format 

Syntax :- 

mktime(hour, minute, second, month, day, year)
 
date(format,timestamp)


 data () funtion 

 d = Represents the day of month (1 to 31)
m = Represen
ts a month (1 to 12)
y = Represents a year (4 digits)
l = Represents the day of the  week


Time () Function :-

   Returns the Current time in the  number of the  seconds 
  time() function  used return the courrent time 


H - 24 - hour (00 to 23)
i - Minutes with (00 to 59)
s - Second with leading (00 to 59 )
a - Lowercase ante meridiem and post meridiem (am to pm)


    Default timezone 

      date _default_timezone_set('UTC');

        ፨ Default Timezone UTC 

   ஃ Current date and time

        $currentDateTime = date('Y-m-d H:i:s') ;       

              ፨ YYYY-MM-DD-HH-MM:SS     

   ஃ Current date format

       $currentDate = date('F j,Y');

              Month day , Year

   ஃ Current time 

      $currentTime12Hr = date('h:i:s A');

                hh: mm:ss AM/PM

  
 

  Example :-

<?php
echo "Today is " . date("y/m/d") .  "<br>";
echo "Today is" . date("y.m.d")  .  "<br>";
echo "Today is" . date(y-m-d")  ."<br>";
echo "Today is ". date("l");

?>

 Output :-




 

2] Date :- 

Example 


<?php
$day =date("d/m/y");
echo $day;


 Output :-

 

3]  Day :- 

  Example :-


<?php

echo "Today is ". date("l");

?>

Output :-




  

  4]  Date  :-

Example :-'

<?php

$d= mktime(11,14,54,8,12 ,2014);
echo " date " . date("y-m-d h:i:sa");

?>

Output :-




5]  Date()  Function :-

Example :-


<?php
$date =date ("D . M .D .Y");
print("Date :- <br>". $date);
?>


OutPut :-


6] Date()  Function :-

Example:-


<?php
$date = date("D M d y");

print ("Date :-". $date);
?>

Output :-


7] 

Example:-

<?php
   date_default_timezone_set('UTC');
   
   echo date("l");
   echo "
";
   
   echo date('l dS \of F Y h:i:s A');
   echo "
";
?>

Output :-




Related Post :-

Registration form in php

html color tag