Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

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.

Edited By: prince.gen
09-Apr-10 06:01:39

prince.gen
Beginner Modder
ranks
useravatar
Offline
10 Posts
Administrator has disabled public posting

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

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

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.

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

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.

prince.gen
Beginner Modder
ranks
useravatar
Offline
10 Posts
Administrator has disabled public posting

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

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5913
Dormant:
User Info:
 
Total Users:
10778
Newest User:
negina4qx
Members Online:
0
Guests Online:
246

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