0

I'd like to know if this stands correctly, I am wanting to set rand(1,100) to be 100 for specific pages and I'm unsure if I have done it correctly..

$rand = rand(1, 100);

if( basename($_SERVER['PHP_SELF'], '.php') == 'index' ) #index.php
{   
    $rand = 100;
}

if ($rand > 20)
{
    echo 'Yes it works';
} else {
    echo 'no it does not work';
}

So if index.php loads, will $rand be set to 100 always with the if statement that I wrote? or would it need to be $rand > 100;

iBrazilian2
  • 2,204
  • 6
  • 23
  • 45

1 Answers1

0

Yes.

$rand will always be 100 when the requested file is index.php (no matter the path, i.e /index.php or /some/path/index.php).

There is also a chance that $rand will be 100 even when it is not index.php that was requested, due to the parameters passed to the rand() function call.

This can be easily tested: PHP server on local machine

Community
  • 1
  • 1
Jonathan Dixon
  • 2,316
  • 23
  • 29