Need help with variables!
2015-04-14, 12:42 AM,
#1
Hey elites,

I'm stuck with finish one of my sites. I've searched google and cpaelites, but haven't found anything related to that. Also I don't even know how to google my problem..

I have a site with a like button on it. What I want is to change the fanpage url for every visitor.

SO if the code goes like this: facebook.com/[ID_of_a_page], I want it to to be something like facebook.com/[variable1]

Next:

variable2=[ID_of_my_first_page]
variable3=[ID_of_my_second_page]

Finally:

Varible 1 will switch from Var2 to Var3 for every visitor.

Visitor number 1 will have to like my page with the id from Var2, 2nd visitor will like my page with the id from Var3, 3rd visitor again from Var2 and so on...

What i need?

1)this rotation code that rotates between variables!
2)how to properly name, write and add value to this variables!

Hope you understand it, and thanks in advance!

P.S.: I want my sites to remain private, so please don't PM me about them!
Reply
2015-04-14, 01:29 AM,
#2
$variables = array($variable1, $variable2, $variable3);
shuffle($variables);
facebook.com/<?php echo $variables[0]; ?>
Latest Thanks - View all

konker5(2015-04-14 02:28 AM) 
Reply
2015-04-14, 01:48 AM,
#3
Hope this helps!

1) To get the variable to switch you will need some kind of variable to count each visitor or click.

2) The code below solves both your problems, you can change the variables to any name you like.

'$url' = this holds the first part of the URL
'$page1' = this is a variable to which contains the second half of the url

'$count % 2 == 0' this uses modulo to check if the number is even or not.

PHP Code:
// Make sure you add a '/' to the end of the url variable.
// You can change echo to a variable if that's how you want it.
if ($counter == 0) {
    echo 
$url $page2;
// This outputs the url link with the second page id
} else {
    echo 
$url $page1;
// This outputs the url link with the first page id

Latest Thanks - View all

konker5(2015-04-14 02:28 AM) 
Reply
2015-04-14, 02:09 AM,
#4
(2015-04-14, 01:29 AM)tirycm Wrote: $variables = array($variable1, $variable2, $variable3);
shuffle($variables);
facebook.com/<?php echo $variables[0]; ?>

Hey, thanks for the answer! I really like this code, but it seems it uses randomness as a factor. On a bigger traffic scale it should result with even variables usage! So thank you very much!

(2015-04-14, 01:48 AM)Rothschild Wrote: Hope this helps!

1) To get the variable to switch you will need some kind of variable to count each visitor or click.

2) The code below solves both your problems, you can change the variables to any name you like.

'$url' = this holds the first part of the URL
'$page1' = this is a variable to which contains the second half of the url

'$count % 2 == 0' this uses modulo to check if the number is even or not.

PHP Code:
// Make sure you add a '/' to the end of the url variable.
// You can change echo to a variable if that's how you want it.
if ($counter == 0) {
    echo 
$url $page2;
// This outputs the url link with the second page id
} else {
    echo 
$url $page1;
// This outputs the url link with the first page id


Hey, thanks for taking your time to answer. Thanks for making this code simple, but I have a question regarding this counter. Will the counter reset for every new visitor? Or will it continue regardless?

If it resets for every visitor this is kinda useless, because it will "echo" the same $page for every visitor unless he refreshes the site to get a different result from your modulo.
Reply
2015-04-14, 02:57 AM,
(This post was last modified: 2015-04-14, 02:58 AM by tirycm.)
#5
Create a file with name count.txt and write 1 in it.
$variables = array("variable1", "variable2", "variable3");
$file = "count.txt";

if (file_get_contents($file) === "1" ){
echo $variables[0];
file_put_contents($file, "2");
}
else if (file_get_contents($file) === "2" ){
echo $variables[1];
file_put_contents($file, "3");
}
else if (file_get_contents($file) === "3" ){
echo $variables[2];
file_put_contents($file, "1");
}
Latest Thanks - View all

konker5(2015-04-14 03:07 AM) 
Reply
2015-04-14, 04:34 AM,
#6
(2015-04-14, 02:09 AM)daryo Wrote:
(2015-04-14, 01:29 AM)tirycm Wrote: $variables = array($variable1, $variable2, $variable3);
shuffle($variables);
facebook.com/<?php echo $variables[0]; ?>

Hey, thanks for the answer! I really like this code, but it seems it uses randomness as a factor. On a bigger traffic scale it should result with even variables usage! So thank you very much!

(2015-04-14, 01:48 AM)Rothschild Wrote: Hope this helps!

1) To get the variable to switch you will need some kind of variable to count each visitor or click.

2) The code below solves both your problems, you can change the variables to any name you like.

'$url' = this holds the first part of the URL
'$page1' = this is a variable to which contains the second half of the url

'$count % 2 == 0' this uses modulo to check if the number is even or not.

PHP Code:
// Make sure you add a '/' to the end of the url variable.
// You can change echo to a variable if that's how you want it.
if ($counter == 0) {
    echo 
$url $page2;
// This outputs the url link with the second page id
} else {
    echo 
$url $page1;
// This outputs the url link with the first page id


Hey, thanks for taking your time to answer. Thanks for making this code simple, but I have a question regarding this counter. Will the counter reset for every new visitor? Or will it continue regardless?

If it resets for every visitor this is kinda useless, because it will "echo" the same $page for every visitor unless he refreshes the site to get a different result from your modulo.

You could keep track of it using a DB if your site is using one? I can't think of another good way to store the count.

The 'echo' put can be replaced and you could have it as a variable to be used... So instead of 'echo' it would show like:

PHP Code:
// Before
echo $url $page2;
// After
$fullURL $url $page2

Then you can call the variable somewhere else to be displayed
Latest Thanks - View all

konker5(2015-04-14 04:54 AM) 
Reply
2015-04-17, 04:40 PM,
#7
i can help you dude
if you want
Reply





About Us | Contact Us | CPA Elites | Advertise | Stats | Staff Team

© 2013-2017 CPA Elites Ltd
Enhanced by MyBB and WallBB
Return to top