I’m attempting to find the $_POST variables in a line of code using strstr. Basically user submits a code, and my program searches to find $_POST in their code, of course strstr only finds the first occurrence but still. There is a simple HTML form that carries the code over to my PHP script. this is how I am doing it:
$user_submit=$_POST['submit'];//code posted
$post="$_POST";//used for post search
/*search code for $_POST*/
if(strstr($user_submit,$post)){
echo "found " . $post . ".";}
else{
echo "No " . $post . " found.";}
I am getting No Array found.0 error. perhaps I am using strstr wrong, I am new to sifting through strings, all help is appreciated.
It’s because of variable substitution. In PHP, including anything that looks like a variable identifier, such as $variable or $_POST, in a string literal will have its value substituted into the string.
So what’s happening is $_POST in that string is getting replaced by PHP converting the $_POST variable to its string representation, which isn’t $_POST and which is thus not matching anything.
You can use single quotes to avoid this, or I believe escaping the $ character.