1

sorry I am new to PHP. I would like my code to randomly select from these: '/post371/', '/post375/', '/post377/',

but when I tried to access my url it redirects to https://example.com0 , https://example.com1, https://example.com2.

Instead of, https://example.com/post371/ , https://example.com/post375/ , https://example.com/post377/

Here's my code:

<?php        
$pagez = array(
        '/post371/',
        '/post375/',
        '/post377/',
    );
    
    if(empty($_GET['redir'])) {
        $_GET['redir'] = base64_encode(home_url() . array_rand($pagez));
    }
?>


    <form id="landing" method="POST" action="<?php echo base64_decode($_GET['redir']); ?>">
        <input type="hidden" name="newwpsafelink" value="<?php echo $_GET['code'] ?>">
    </form>
    <script>
        window.onload = function() {
            document.getElementById('landing').submit();
        }
    </script>

Thank You!

2 Answers 2

3

array_rand returns a random key from the array

Try this : $_GET['redir'] = base64_encode(home_url() . $pagez[array_rand($pagez)])

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

Comments

1

The array_rand function returns a random key from the array. You're really close already - just access the returned element like so:

$_GET['redir'] = base64_encode(home_url() . $pagez[array_rand($pagez))];

1 Comment

Thanks this works: $pagez[array_rand($pagez)]);

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.