Answers for "php url info"

PHP
2

php get url path name

parse_url( $_SERVER[ 'REQUEST_URI' ], PHP_URL_PATH );
Posted by: Guest on November-04-2020
1

php get url infos

$url = 'http://username:password@hostname:9090/path?argument=value#fragment';
var_dump(parse_url($url, PHP_URL_SCHEME));   // http
var_dump(parse_url($url, PHP_URL_USER));     // username 
var_dump(parse_url($url, PHP_URL_PASS));     // password
var_dump(parse_url($url, PHP_URL_HOST));     // hostname
var_dump(parse_url($url, PHP_URL_PORT));     // 9090
var_dump(parse_url($url, PHP_URL_PATH));     // /path
var_dump(parse_url($url, PHP_URL_QUERY));    // argument=value
var_dump(parse_url($url, PHP_URL_FRAGMENT)); // fragment

// You can use "parse_str" to parse the URL Query to an Array
$query = parse_url($url, PHP_URL_QUERY);
$queryArray = array();
parse_str($query, $queryArray);
var_dump($queryArray);  // array('argument' => 'value')
Posted by: Guest on July-30-2021
1

if browser url is having query string after domain name in it check using php

$url = $_SERVER['REQUEST_URI'];

if (!strpos($url,'mysql')) {
echo 'No mysql.'; //swapped with other echo statement
} else {
echo 'Mysql exists.';
}
Posted by: Guest on December-04-2020

Browse Popular Code Answers by Language