0

Alright, so i have this code:

<?php
$p = 65536;
$p2 = 33554432;
if($p & $p2){
echo "True";
}else{
echo "False";
}
?>

Alright so if i put the numbers in the script the output is "False", but when i use $_GET,$_POST, etc it returns "True" even if i put the numbers in quotes.

whats the problem? Any help is appreciated!

3
  • 1
    This has to be the worst (while still being accurate) title :) Commented Sep 20, 2012 at 1:42
  • Can you please clarify the expected input/output, and the unexpected result you're seeing? I'm not sure if your problem is with the code example you provided, or with a different version of the script involving $_GET Commented Sep 20, 2012 at 1:44
  • Where are you using $_GET or $_POST? Have you verified that they have the values you think they do? Commented Sep 20, 2012 at 1:45

2 Answers 2

3

Elements of $_GET and $_POST are strings. If you read the docs, it converts each character into its ordinal position, hits them with the bitwise operator, and converts back to a character.

You should call intval() on the values first.

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

Comments

2

You need to cast them to int, or you are doing & with two strings.

$p = (int)$_GET['p'];
$p2 = (int)$_GET['p2'];
if ($p & $p2) {
  // ...

Comments

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.