Answers for "how to get url parameters in php"

PHP
3

Get Parameters From a URL String in PHP

phpCopy<?php 
echo $_GET['email'] . $_GET['name']
?>
Posted by: Guest on April-23-2021
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
1

Get Parameters From a URL String in PHP

phpCopy<?php 
$url = "https://testurl.com/test/[email protected]&name=sarah";
$components = parse_url($url);
parse_str($components['query'], $results);
print_r($results); 
?>
Posted by: Guest on April-23-2021
0

Get Parameters From a URL String in PHP

phpCopy<?php 
$url = "https://testurl.com/test/[email protected]&name=sarah";
$components = parse_url($url);
parse_str($components['query'], $results);
echo($results['email']); 
?>
Posted by: Guest on April-23-2021
0

Get Parameters From a URL String in PHP

phpCopy<?php 
$url = "https://testurl.com/test/[email protected]&name=sarah";
$components = parse_url($url, PHP_URL_QUERY);
//$component parameter is PHP_URL_QUERY
parse_str($components, $results);
print_r($results); 
?>
Posted by: Guest on April-23-2021
0

php url parameters

<form action="/" method="get">
  <input type="text" name="search" placeholder="Search...">
  <input type="submit">
</form>
<?php 
  echo $_GET["search"]
?>
Posted by: Guest on August-26-2021

Code answers related to "how to get url parameters in php"

Browse Popular Code Answers by Language