使用头函数重定向变量php

how do i send a php variable (boolean) with a redirect. For example a flag is set if a condition is true

if($url = 'someurl.com'){
   $flag = true;
    header('Location: newpage.php?$flag');
    exit();
}

then mypage.php needs to check if its true or false to execute a function

i tried this but it doesn't work

header('Location: mypage.php?$flag');

perhaps there is a better way of doing it?, this is the 2nd redirect on the page, the first redirect checks checks for a login, then it proceeds to check the $flag variable, no output has been done at this stage

thanks in advance for any advice

Sending true in a variable wont work for this, you have to set it to $flag="true" and you have to use double quotes.

And a single equals means your setting a variable 2 equals means your checking if a variable is equal to something

if($url == 'someurl.com'){
   $flag = "true";
    header("Location: newpage.php?$flag");
    exit();
}

Variables don't work in single quotes - Also you need to use a comparison operator in an if statement - not an assignment:

if($url == 'someurl.com')
{
    $flag = 'someText';
    header("Location: newpage.php?$flag");
    exit();
}

or

header('Location: mypage.php?'.$flag);

try == operator to check in if() and variable need to correct add with header url use concat(.)

if($url == 'someurl.com'){

and

header('Location: newpage.php?'.$flag);

You need to concatenate php variable with string using dot(.) operator.

Try this.

header('Location: newpage.php?'.$flag);

Also check your condition with comparison operator(==)

  if($url == 'someurl.com') {
     ....
  }

$url = 'someurl.com' it means assigning a string into $url

Change your if condition to

 if($url == 'someurl.com'){ ....

And the set the header as

 header('Location: mypage.php?flag='.$flag);
$flag = '1';
header('Location: newpage.php?flag='.$flag);

Then in newpage.php, check with $_GET['flag'].