Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » load a module once in a day for a...
load a module once in a day for a every user or every ip
load a module once in a day for a every user or every ip
I want to load a module once in a day for a every user or every ip. I mean if any user comes to my website that module shows once in a day. Is this possible. Pls help me. Tks.
09-Apr-10 07:01:39
Re: load a module once in a day for a every user or every ip
Hi Prince.gen,
try this:
$seconds = 24*60*60; // time period in seconds (24*60*60 is 1 day)
$c = JRequest::getInt('SeenIt', 0, 'cookie');
if ($c) return; /* if cookie was set, don't show anything, else... */
setcookie( 'SeenIt', 1, time()+$seconds, '/' );
return XXX; /* return module XXX, but once per time period */
replace XXX with the module id that you want to include.
Cheers,
Stephen
Re: load a module once in a day for a every user or every ip
p.s. this doesn't check IP address - it uses a cookie for every user that comes onto the site, therefore remembers their particular web browser for a day. If the machine is a shared machine, and cookies are shared between users then Joomla won't be able to tell the difference and will still only show the module once per day for that particular client machine.
Re: load a module once in a day for a every user or every ip
Thank you so much for your help.
Now I am using this code:
********************************
/* set a different "instance name" for each module that you want to show only once */
$instance_name = "shown_module_1";
if (!isset($_SESSION[$instance_name]) ||
$_SESSION[$instance_name] == false) {
$_SESSION[$instance_name] = true;
/* customise "101" to your own module number.
* This is the one that gets shown just once per session.
*/
return xxx;
}
*******************************
Can you pls tell me what is the deference between your code and this code???
Thanks.
Re: load a module once in a day for a every user or every ip
The difference is that in the code I posted, it uses a cookie (not a session), and that cookie expires after 1 day. With your code, the user will get the module once per session. So if they have 2 sessions in 1 day, they will see it on the first page of each session.
In the new code, it doesn't matter how many sessions there are in 1 day - they only see the module once per day.
Cheers,
Stephen
- Index
- » MetaMod
- » MetaMod General Support
- » load a module once in a day for a...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5944
- Posts this week:
- 2
- User Info:
- Total Users:
- 7658
- Newest User:
- carre82601
- Members Online:
- 0
- Guests Online:
- 166
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked