DEV Community 👩‍💻👨‍💻

Leopold Degtyarev
Leopold Degtyarev

Posted on

PHP: How to change header randomly on each load?

THIS IS IN THE START OF INDEX.PHP:
<?php
if(!isset($_GET['code'])){
header('location: index.php?code=900');
}

THIS IS WHERE THE BUTTON IS:
<a href="http://<?php echo $_GET['code'] ?>.dev.test.com/">click here</a>

What I'm trying to do is, when it requests 'code' to have multiple options to choose from and randomly select (ex. code=900, code=200). I tried with array but I always get error.

Any suggestions? Help is much appreciated. Thanks.

Top comments (3)

Collapse
 
simonced profile image
simonced

As @tmblog said, what error do you have?

And, is that

http://<?php echo $_GET['code'] ?>.dev.test.com

type of URL setup on your webserver?

If you use Apache, maybe you need a rewrite rule to turn that address into:

http://dev.test.com?=code=$1

where $1 is the capturing group of the rewrite rule.

Please provide more details.

Collapse
 
tmblog profile image
tmblog

What's the error you get?

Collapse
 
devdrake0 profile image
Si

Can you update your question with more detail please. If not done in 24 hours, the #help tag will be removed.

16 Libraries You Should Know as a React Developer

>> Check out this classic DEV post <<