[PHP Function] Is there such a function?
Hi there all! :D
I was just wondering, is there like a function that returns all current sessions?
Maybe something like a session_array() which returns something like
Array
(
guest => Array ( )
admin => Array ( )
)
Or maybe like a session_count($session_name), where if you did $_SESSION['guest'], and you did session_count("guest"), it would return the number of those sessions?
Any help is appreciated.
Re: [PHP Function] Is there such a function?
So basically you want a function that returns all session variable?
Just wanna make sure
Re: [PHP Function] Is there such a function?
Yeah, cuz i'm doing something like
if(!isset($_SESSION['id']))
$_SESSION['memgroupid'] = 1;//Guest MemberGroup ID
function getGuests()
{
//Count memgroupid sessions with a value of 1.
}
Re: [PHP Function] Is there such a function?
OK. You can print all session variable with this:
PHP Code:
<?php
session_start();
Print_r ($_SESSION);
?>
Maybe this is what you need
Re: [PHP Function] Is there such a function?
hmmm...
Then could I do
count($_SESSION['memgroupid'])?
It's that easy?
:O:
Re: [PHP Function] Is there such a function?
Btw I am still not sure what you are trying to do.
You can try to
Re: [PHP Function] Is there such a function?
Basically, if a guest comes to my site, I set them with the session memgroupid, with the value of 1 (in the mysql db, 1 is the guest group)
Now, in an infobox, I want it to show the amount of guests.
So would I do count($_SESSION['memgroupid'])?
Does that even work? O_O
Re: [PHP Function] Is there such a function?
Ok, thanks. :D
Butjust to make sure...
http://71.141.99.165/test.php
What number do you see?
Re: [PHP Function] Is there such a function?
I see a 1. You're doing it wrong.
Re: [PHP Function] Is there such a function?
Well, this is my code:
PHP Code:
<?php
session_start();
$_SESSION['mem'] = 1;
echo count($_SESSION['mem']);
?>
what's wrong?
Re: [PHP Function] Is there such a function?
The function count() counts the number of values stored in an array. You're not using it correctly. Here's a good tutorial: http://www.devarticles.com/c/a/PHP/T...line-With-PHP/
Re: [PHP Function] Is there such a function?
But isn't $_SESSION['memgroupid'] an array?
When I print_r $_SESSION, memgroupid is an array.
---------- Post added at 04:55 PM ---------- Previous post was at 04:48 PM ----------
About http://www.devarticles.com/c/a/PHP/T...line-With-PHP/,
how do i make it read $_SESSIONs with only $_SESSION['memgroupid'], and not every single session file?
Re: [PHP Function] Is there such a function?
yes, follow murawd. in summary - each array must be treated in a variable as a value. for that you will need to loop a sequence to initialise every variable for each array - read the tutorial murawd has directed you.
Posted via Mobile Device
Re: [PHP Function] Is there such a function?
Quote:
Originally Posted by
simplebb
:o :o :o
Re: [PHP Function] Is there such a function?
Ohh... I got what SimpleBB wants to do.
Basically he wants to show number of guests on web-site.
I have an idea how to make it in head, but can't explain it cause of my english ...
Re: [PHP Function] Is there such a function?
Try.
It'll be good for your english, to try.
Most importantly, it'll help me! >:D
Re: [PHP Function] Is there such a function?
Here is guide that will help. But sucks that it requires mysql.
http://www.newbiesparadise.com/tutor...ts-online.html
If you want you can change that script a little bit and make it write data in txt file
Re: [PHP Function] Is there such a function?
try
$array = $_SESSION['memgroupid'];
$count = count($array);
for($i = 0;$i < $count;$i++)
{ print "$i"; }
as simple as that, i should think. I have not worked on web page coding for a year, and i miss the excitement of solving problems, the harder the better.
Posted via Mobile Device
Re: [PHP Function] Is there such a function?
Quote:
Originally Posted by
IQstim
try
$array = $_SESSION['memgroupid'];
$count = count($array);
for($i = 0;$i < $count;$i++)
{ print "$i"; }
as simple as that, i should think. I have not worked on web page coding for a year, and i miss the excitement of solving problems, the harder the better.
Posted via Mobile Device
Doesn't work.
Anyyways, i now know that counting it won't work, cuz the memgroupid goes into session once, not equal to the amount of sessions.
Re: [PHP Function] Is there such a function?
Quote:
Originally Posted by
SimpleBB
Doesn't work.
Anyyways, i now know that counting it won't work, cuz the memgroupid goes into session once, not equal to the amount of sessions.
check the link that i have sent in my previous post.
That should help you
Re: [PHP Function] Is there such a function?
That does seem to work.
Does anyone else have a faster or possibly, a solution that will get guests faster, with less memory usage?
Re: [PHP Function] Is there such a function?
Check this: http://98.246.30.179/test.php
I have setted this up using guide from here: http://www.newbiesparadise.com/tutor...ts-online.html
Everything works perfectly ;)
Re: [PHP Function] Is there such a function?
Lol, who's the other person?
Re: [PHP Function] Is there such a function?
me and you
there were other 2-3 persons