zero-perfoliate
zero-perfoliate

Author Topic: Question: Custom Server Variables (multi-user session variables)  (Read 495 times)

Offline RoseKnight

  • PHP Help Guru's
  • ****
  • Posts: 52
  • Karma: +0/-0
I was playing around with $_SESSION variables in php and was wondering how/if one could make a a variable that would apply to anybody accessing the page. Therefore retaining the individuality of the $_SESSION variables.

If possible: As a simple example: how would you make a script that has a variable that counts how many times a page has been loaded as well as how many times a particular user has loaded that page?
I have code below that gives the intended result, but I don't like sacrificing the individuality of the $_SESSION variables.

any help is greatly appreciated.

Code: [Select]
<?php

session_id("global");
session_name("global");
session_start();

//global variable
if (!isset($_SESSION['global_count'])) {
  
$_SESSION['global_count'] = 1;
} else {
  
$_SESSION['global_count']++;
//end if

$global_count $_SESSION['global_count'];

//individual variable using user's ip address as an id
$id str_replace(".""-"$_SERVER['REMOTE_ADDR']);

if (!isset($_SESSION['individual_count'])) {
$individual_array = array($id => 1);
  

} else {
  
$individual_array $_SESSION['individual_count'];

  
if (!isset($individual_array[$id])) {
  
$individual_array[$id] = 1;
  
} else {
  
$individual_array[$id]++;
  
//end if
  
//end if
  

$_SESSION['individual_count'] = $individual_array;

echo "global count: ".$global_count."<br />";
echo "individual count: ".$individual_array[$id];

exit(0);
?>


hotnoob

  • Guest
Re: Question: Custom Server Variables (multi-user session variables)
« Reply #1 on: March 20, 2010, 12:36:12 AM »
your better off using mysql, or if you don't have a mysql database, than a text file to store the view count.

sessions use a whole bunch of temp files anyway, so your probably better off just using a text file, opening and updating it every time a page is loaded...

So, the easiest solution is to use a mysql database... or even mssql or whatever database you prefer...

Offline RoseKnight

  • PHP Help Guru's
  • ****
  • Posts: 52
  • Karma: +0/-0
Re: Question: Custom Server Variables (multi-user session variables)
« Reply #2 on: March 20, 2010, 08:46:17 AM »
I've spent a few days reading on the ups and downs of $_SESSION's and I guess I assumed it was stored in memory. Too bad too bad. Thanks for the input! Back to the drawing board. :0

Offline RoseKnight

  • PHP Help Guru's
  • ****
  • Posts: 52
  • Karma: +0/-0
Re: Question: Custom Server Variables (multi-user session variables)
« Reply #3 on: March 21, 2010, 06:45:58 AM »
as a side note, this ~ is a tilde and this ` is an acute . How did I mix those two up? sorry... (:

hotnoob

  • Guest
Re: Question: Custom Server Variables (multi-user session variables)
« Reply #4 on: March 22, 2010, 12:10:32 PM »
Sessions are still very important tho...

Well... I use cookies as a secondary verification method on most of my websites.. so i can't say i use sessions often :P

all i do is use md5 on the users password after it's gone through an algorithm to determine which parts of the password are included; and i can't say what determines the algorithm :P

The cookie is just for keeping the verification linked to the browser...

Than in the mysql databases, i keep a hold of the users host (network information)

damn, i'm ranting again :P

Offline RoseKnight

  • PHP Help Guru's
  • ****
  • Posts: 52
  • Karma: +0/-0
Re: Question: Custom Server Variables (multi-user session variables)
« Reply #5 on: March 22, 2010, 06:01:27 PM »
Indeed rant.
I'm working on a basic text based game and am using $_session to stay logged in so i don't have to use constant calls for info from the database just to put it back.

but I'm sure once i get to the end of the creation step of the game, I'll have to use the encryption algorithms or something like that. Maybe find a better way to stay logged in too.

 

zero-perfoliate