Answers for "get request in php"

PHP
5

php get

#Get Method and Post Data

Send data through get and Post

$_GET Example
============
<?php
if(isset($_GET['name'])){
echo htmlentities($_GET['name']);
//or
//$name = htmlentities($_GET['name']);
//echo $name
print_r($_GET);
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>Get post website</title>
    </head>
<body>
    <form method="GET action=get_post.php">
        <div>
            <label>Name</label><br>
            <input type="text" name ="name">
        </div>
        <div>
            <label>Email</label><br>
            <input type="text" name ="email">
        </div>
        <input type="submit" value ="Submit">
    </form>
</body>
</html>
================
$_POST Example
================
<?php
if(isset($_GET['name'])){
//echo htmlentities($_GET['name']);
//or
//$name = htmlentities($_GET['name']);
//echo $name
//print_r($_GET);
}

if(isset($_POST['name'])){
    $name = htmlentities($_POST['name']);
    echo $name;
    print_r($_POST);
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>Get post website</title>
    </head>
<body>
    <form method="POST" action="get_post.php">
        <div>
            <label>Name</label><br>
            <input type="text" name ="name">
        </div>
        <div>
            <label>Email</label><br>
            <input type="text" name ="email">
        </div>
        <input type="submit" value ="Submit">
    </form>
</body>
</html>
================
$_REQUEST Example  //another uncommon way to do it. This is not 
  //normally done this way
================
<?php
if(isset($_REQUEST['name'])){
    $name = htmlentities($_REQUEST['name']);
    echo $name;
    print_r($_REQUEST);
}

?>
<!DOCTYPE html>
<html>
<head>
    <title>Get post website</title>
    </head>
<body>
    <form method="POST" action="get_post.php">
        <div>
            <label>Name</label><br>
            <input type="text" name ="name">
        </div>
        <div>
            <label>Email</label><br>
            <input type="text" name ="email">
        </div>
        <input type="submit" value ="Submit">
    </form>
</body>
</html>
================
$_SERVER['QUERY_STRING']  Example
================
<?php
echo $_SERVER['QUERY_STRING'];


?>
<!DOCTYPE html>
<html>
<head>
    <title>Get post website</title>
    </head>
<body>
    <form method="POST" action="get_post.php">
        <div>
            <label>Name</label><br>
            <input type="text" name ="name">
        </div>
        <div>
            <label>Email</label><br>
            <input type="text" name ="email">
        </div>
        <input type="submit" value ="Submit">
    </form>
</body>
</html>
Posted by: Guest on May-13-2020
5

post request php

$response = httpPost("http://mywebsite.com/update.php",
	array("first_name"=>"Bob","last_name"=>"Dillon")
);

//using php curl (sudo apt-get install php-curl) 
function httpPost($url, $data){
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($curl);
    curl_close($curl);
    return $response;
}
Posted by: Guest on August-03-2020
19

php get

<form action="/" method="get">
  <input type="text" name="name">
  <br>
  <input type="submit">
</form>
<?php
  echo $_GET["query"];
?>
Posted by: Guest on October-03-2020
0

what does $request do in php

$message = "";

if($_REQUEST['msg'] == "new"){
    $message = "New User has been added successfully";
}else if($_REQUEST['msg'] == 'edit'){
    $message = "User has been saved successfully";
}else if($_REQUEST['msg'] == 'update'){
    $message = "User(s) has been Updated successfully";
}
Posted by: Guest on May-29-2020
0

php get data from url

// previous link 
<a href="test_get.php?subject=PHP&web=W3schools.com">Test $GET</a>
// the code
<?php
echo "Study " . $_GET['subject'] . " at " . $_GET['web'];
?>
Posted by: Guest on November-03-2020

Browse Popular Code Answers by Language