PDA

Click to See Complete Forum and Search --> : Post only


slice
Mar 1st, 2006, 10:48 AM
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.

visualAd
Mar 1st, 2006, 01:44 PM
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.

$var = $_POST['form_var_name'];

Winsocket
Mar 9th, 2006, 10:38 AM
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
$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.");
}
?>

PlaGuE
Mar 9th, 2006, 04:21 PM
i see an error already...

fwrite ($fp, "$_SERVER['REMOTE_ADDR']");

should be

fwrite ($fp, "$_SERVER[REMOTE_ADDR]");
or
fwrite ($fp, $_SERVER['REMOTE_ADDR']);

visualAd
Mar 9th, 2006, 05:20 PM
fwrite ($fp, "$_SERVER[REMOTE_ADDR]");


You shouldn't use that either, you have not included REMOTE_ADDR in quotes. This would be correct:

"{$_SERVER['REMOTE_ADDR']}"

Winsocket
Mar 9th, 2006, 06:07 PM
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
$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!");
}
?>