How to enforce that visitor is not using query string to access the page instead using post method only.
I don't want visitor should go thru GET method.
Printable View
How to enforce that visitor is not using query string to access the page instead using post method only.
I don't want visitor should go thru GET method.
All variables from the query string are loaded into the $_GET array and all variables from the HTTP body in a POST request are loaded into $_POST. If you want to ensure that your users are using a post request, use the $_POST array.
PHP Code:$var = $_POST['form_var_name'];
This is a bit of code i wrote so if the users uses a GET request then it writes their IP to a text file!
PHP Code:<?php
$ipbanfile = "/home/site/public_html/Ipban.ban"; #IP Ban File
if($_SERVER['REQUEST_METHOD'] == "GET"){
$fp = fopen($ipbanfile, "a+");
fwrite ($fp, "{$_SERVER['REMOTE_ADDR']}");
fclose($fp);
die("So close... yet so far.");
}
?>
i see an error already...
PHP Code:fwrite ($fp, "$_SERVER['REMOTE_ADDR']");
should be
fwrite ($fp, "$_SERVER[REMOTE_ADDR]");
or
fwrite ($fp, $_SERVER['REMOTE_ADDR']);
You shouldn't use that either, you have not included REMOTE_ADDR in quotes. This would be correct:Code:fwrite ($fp, "$_SERVER[REMOTE_ADDR]");
"{$_SERVER['REMOTE_ADDR']}"
Yeah, edited it, sorry i wrote that from memory. Simple mistake :p I also didn't need the extra die(); and exit(); so edited that as well. so...PHP Code:<?php
$ipbanfile = "/home/site/public_html/Ipban.ban"; #IP Ban File
if($_SERVER['REQUEST_METHOD'] == "GET"){
$fp = fopen($ipbanfile, "a+");
fwrite ($fp, "{$_SERVER['REMOTE_ADDR']}");
fclose($fp);
die("Please do not use the GET method!");
}
?>