How to finish the php script split test website?

Hi all. Tell me how make a script that would when you refresh the page, the user saw only one version of the site, that is what the browser remembered it cooke

the script itself is very simple, found in the Internet which simply changes the url of the page
<?php
 $Pages = array(
 'http://yandex.ru' , 
'http://google.ru'
);
 $MaxRandom = getrandmax();
 $RandomValue = intval( rand( 0 , count( $Pages ) - 1 ) );
 header( 'Location: '.$Pages[ $RandomValue ] );
?>
Here $Pages
April 7th 20 at 11:06
2 answers
April 7th 20 at 11:08
Solution
// Set Cookie for one hour after installation:
SetCookie("my_site_cookie", "hello cookie!", time()+3600);


// read
if (isset($_COOKIE['my_site_cookie']))
echo "Hello, cookie owner!";
The full version will look like?
<?php
 SetCookie("http://yandex.ru", "http://google.ru", time()+3600);

 if (isset($_COOKIE['http://yandex.ru']))
 echo "http://yandex.ru";

 $Pages = array(
 'http://yandex.ru' , 
'http://google.ru'
);
 $MaxRandom = getrandmax();
 $RandomValue = intval( rand( 0 , count( $Pages ) - 1 ) );
 header( 'Location: '.$Pages[ $RandomValue ] );
?>


Please fill in the code and I'm looking for a response - Amaya_Welch commented on April 7th 20 at 11:11
I think something like that )

if (!isset($_COOKIE['redirect_cookie']))
{
$pages =['http://yandex.ru' , 'http://google.ru'];
$redirect = $pages[array_rand($pages)];
SetCookie("redirect_cookie", $redirect, time()+3600));
}
 header( 'Location: '.$_COOKIE['redirect_cookie']);
- hector34 commented on April 7th 20 at 11:14
if (!isset($_COOKIE['redirect_cookie']))
{
$pages =['http://yandex.ru' , 'http://google.ru'];
$redirect = $pages[array_rand($pages)];
SetCookie("redirect_cookie", $redirect, time()+3600));
}
 header( 'Location: '.$_COOKIE['redirect_cookie']);


added code to the file ab-test.php it gives an error... - Amaya_Welch commented on April 7th 20 at 11:17
@Amaya_Welch,

well, I told you a General view I wrote... the syntax is not checked )). try this :

if (!isset($_COOKIE['redirect_cookie'])) {
 $pages = ['http://yandex.ru', 'http://google.ru'];
 $redirect = $pages[array_rand($pages)];
 SetCookie("redirect_cookie", $redirect, time() + 3600);
}

 header('Location:' . $_COOKIE['redirect_cookie']);
- hector34 commented on April 7th 20 at 11:20
@hector34,
Yes, now remember, but one version of the site is not loading for some reason just a white screen. After the update open page 2, delete cookies again white screen. what could it be? - Amaya_Welch commented on April 7th 20 at 11:23
@Amaya_Welch,
try this :
if (isset($_COOKIE['redirect_cookie']))
 $url = $_COOKIE['redirect_cookie'];
 else {
 $pages = ['http://yandex.ru', 'http://google.ru'];
 $redirect = $pages[array_rand($pages)];
 SetCookie("redirect_cookie", $redirect, time() + 3600);
 $url = $redirect;
}

 header('Location:' . $url);
- hector34 commented on April 7th 20 at 11:26
@hector34,
Excellent, thank you very much, it works. Tell, website will seem 50: 50 i.e. if I run an ad, the traffic will approximately equally share? - Amaya_Welch commented on April 7th 20 at 11:29
@Amaya_Welch,
Another question is it possible to implement whatever domain has not changed, but the implementation was the same single site light, second dark, now the domain shows site.ru/index1.html and site.ru/index2.html

And I would like to do that the domain will be the one site.ru but the same scenario on a split test with substitution of pages? - Amaya_Welch commented on April 7th 20 at 11:32
1) array_rand does not guarantee uniform distribution. Although nearly all will more-or-less equally. Want the perfect distribution : save the last used redirect and next time take the one that is used less frequently.

2) do not quite understand the question, but of course you can redirect and pages of your website. Note the life time of the cook. In the examples it is 1 hour. - hector34 commented on April 7th 20 at 11:35
@hector34, the approximate distribution is also normal.
Second question, is there a website with two versions site.ru/index1.html and site.ru/index2.html and when I enter in the browser site.ru/ab-test.php appears index1 or index2 is not saved utm codes, can can the do to there are two versions but the link has not changed site.ru? - Amaya_Welch commented on April 7th 20 at 11:38
@Amaya_Welch, you are generating content on the server. Well, generate it different, depending on cookies. Cook And use the same template , layout ,nested view. Cook B - other pattern , layout ,nested view - hector34 commented on April 7th 20 at 11:41
@hector34Yes you need to learn Php, apparently) - Amaya_Welch commented on April 7th 20 at 11:44
April 7th 20 at 11:10
Thank you found, but how to add in code ?) I'm only superficially familiar with php - Amaya_Welch commented on April 7th 20 at 11:13
@Amaya_Welch, well then contact for freelance or study that would be able to write - myrtis_Casper commented on April 7th 20 at 11:16

Find more questions by tags PHP