Reputation: 7128
I don't know javascript very well. I have a LIKE button.
<a href="" onClick="begen(<?php echo $post->ID; ?>); return false;">LIKE</a>
And,
function begen(id)
{
$.ajax({
type:"POST",
url:"begen.php",
data:"id="+id,
cache:false
});
}
begen() sending id of post to begen.php as a POST header .
I'm checking it with is_integer()
in begen.php for security
if(!is_integer($_POST["id"]))
die("It's not an integer");
When I test it, begen(3) returning "It's not an integer" . I'm not sure why it's (3) not an integer.
http://forum.jquery.com/topic/ajax-sending-json-data-with-boolean-value#14737000000976384 :
HTTP is a text protocol with no concept of bools or ints, so everything needs to be stringified. The stringification of false is certainly not 0.
If everything is a string, how can I be sure that id is really an id
Upvotes: 1
Views: 7410
Reputation: 385264
All GET
and POST
arguments are provided to your script as strings. Were you looking for is_numeric
?
Next time, read the documentation before posting here.
The manual page for is_integer
says:
This function is an alias of:
is_int()
.
The manual page for is_int
says:
To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use
is_numeric()
.
Upvotes: 2