MrUserStack MrUserStack - 7 months ago 50
PHP Question

Meta Refresh IP Address Redirect Once Every 3 IP Addresses

I'm now coming to StackOverflow after trying several forums and searching through at least 80 questions on Stack Overflow for some sort of answer, so please do not mark this as spam.

I am looking to have a META REFRESH redirect activate only once per IP Address, and of this to be one in 3 users.

So every 1 in 3 users is redirected using the META REFRESH, but those IP Addresses would never be redirected ever again.

Is this sort of script possible?


You will want to break this up into tasks, but it is doable. Some words of warning: IP address can change or be shared (think University) but that may be fine for whatever you goal is.

  1. Check if IP address has been redirected before
  2. Use random check to determine if it is the one in three
  3. If it is log it somehow. This example logs it to a file.

I left some stuff in here commented out that is useful for debugging:

// print_r($_SERVER);
//echo $ineligibleIP;
if (strpos($ineligibleIP,$_SERVER['REMOTE_ADDR']) === false) {
    //echo 'Eligible';
    // echo $test;
    if($test==1) {
        file_put_contents('reddit.txt', $ineligibleIP);
echo "Yay, not redirected.";