简体   繁体   English

如何让 PHP 读取 URL

[英]How to get PHP to read URL

I was wondering how I could get a HTML/PHP file to read the URL,我想知道如何获取 HTML/PHP 文件来读取 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) );?我的意思是,假设我在 (index.php) 中有一个搜索功能,它有一个按钮显示显示禁令,它打开了一个新窗口,但是当点击显示禁令时,它发送了一个指向“banaccount.php?id=(idhere)”的链接我怎样才能让 PHP 文件 (Banaccount.php) 识别 ID 并将其作为 PHP 函数 ($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.只需检查“id”是否有值并将其分配给变量。 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.确保安全并且不要试图获取原始值也非常重要,因为您站点上的任何用户都可以向 URL 插入任何不安全的内容。 Use PHP's htmlspecialchars function to convert the unsafe characters to HTML entities.使用 PHP 的htmlspecialchars函数将不安全的字符转换为 HTML 实体。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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