-4

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) );?

Haroon Baig
  • 53
  • 1
  • 9

2 Answers2

0
<?php
if (!isset($_GET['id'])) { /* problem */ exit; }
$id = $_GET['id'];
//... Do something with $id
?>
Shahar
  • 1,687
  • 2
  • 12
  • 18
0

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);
}
hRdCoder
  • 579
  • 7
  • 30