1

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

5
  • 2
    -1: Didn't even bother to look at the documentation for the function, which answers this question right at the top in a large-font note. Commented Jan 10, 2012 at 20:49
  • yes you said this in your answer Commented Jan 10, 2012 at 20:52
  • Yes, and I said it in my comment, too. Commented Jan 10, 2012 at 20:53
  • Yes, you can also tweet about this :) Commented Jan 10, 2012 at 20:55
  • I don't really use Twitter. I might post it to my Facebook wall, though. Commented Jan 10, 2012 at 20:57

1 Answer 1

2

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().

Sign up to request clarification or add additional context in comments.

2 Comments

For edit : i didn't read PHP documentation , because i think i have problem with JS, not PHP
Should have read the documentation for every function involved, as a very initial debugging step.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.