Question:
php variable question?
Bob
2010-11-08 13:55:21 UTC
I want a variable that consist of the same value to all clients. Is there a way to do this without a txt file?

The page will split traffic up into 1/4'ths... So like the variable will initially be 0 but after each user comes it would be incremented by one. If two users come it would be 2, if four users come it would be 0, etc

How do you do this in php?
Three answers:
BigE
2010-11-08 14:23:18 UTC
I believe you will have to use some type of shared construction to get it to go across php sessions. Either a file (as you know), a mysql call, a shared memory call. All these are possible, I believe. I am rather new to PHP.
2010-11-08 22:06:05 UTC
I don't understand your question.



but I'm going to try.



Firstly you can easily create a Global Variable by not constricting its placement.



For example


$name = $_POST['name]';



function blah blah blah

?>



The $name variable is now Global. It is not restricted to a function, or a query.



Now let's move onto the page splitting traffic.



What you want to do is to say,



if x = 0, then href.location('mywebsite.com/index1);



if x = 1, then href.location('mywebsite.com/index2);



if x = 2, then href.location('mywebsite.com/index3');



if x = 3, then href.location('mywebsite.com/index4');



i = 0;

then use an auto-increment to parse the users and deliver them based on variable input from x.
naveed7299
2010-11-09 02:15:42 UTC
You have to store the information somewhere. Text file or database. Even after doing that, you still have to take care of incrementing the counter by one each time a user logs onto the page. For that use this:

session_start();

if(!isset($_SESSION['views']))

{

$_SESSION['views']=1;

//code to increment text file data by one.

}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...