简体   繁体   中英

How to get PHP to read URL

I was wondering how I could get a HTML/PHP file to read the URL,

What I mean is, Let's say I had a Search function in (index.php) that had a button saying Show Bans which opened a New Windows but when clicking Show Bans it sent a link to 'banaccount.php?id=(idhere) how can I get the PHP file (Banaccount.php) to recognise the ID and have it as a PHP function ($id = (idhere) );?

<?php
if (!isset($_GET['id'])) { /* problem */ exit; }
$id = $_GET['id'];
//... Do something with $id
?>

Just check to see if "id" has a value and assign it to a variable. It is also very important that you be safe and not attempt to grab the raw value, as any user on your site can insert anything unsafe to the URL. Use PHP's htmlspecialchars function to convert the unsafe characters to HTML entities.

$id = null;
if (isset($_GET['id'])) {
    $id = htmlspecialchars($_GET['id'], ENT_QUOTES, true);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM