Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » php + once-per-session cookie issue
php + once-per-session cookie issue
php + once-per-session cookie issue
Hi, I'm trying to create a module that will show when someone is within 30 days of their expiration date in CBsubs. CBsubs doesn't have this feature, so until they do, I want to build it with meta_mod.
This is my query:
Code:
<?php
$ user = & JFactory::getUser();
$ db = & JFactory::getDBO();
$ query = "SELEC T b.expiry_date
from #__cbsubs_subscriptions as b
left join #__comprofiler as b on a.user_id = b.user_id
where b.user_id=$user->id";
$ db->setQuery( $query );
$ result = $db->loadObjectList();
?>
It will find the expiry_date of the person logged in and set it as a variable. I then need to have an if/then statement to show this text if the date is <30 days away: "Your membership expires on <expiry_date>! Click here to renew." or "Your membership expires in <x> days!..."
Then use this code to show it once per session:
Code:
session_start();
$instance_name = "cbsubs_expiring";
if (!isset($_SESSION[$instance_name]) ||
$_SESSION[$instance_name] == false) {
$_SESSION[$instance_name] = true;
return 101;
}
Any help is appreciated. I'll post what we find here on CBsubs pages where it will get a lot of use.
15-Feb-12 19:43:18
Re: php + once-per-session cookie issue
Ok, try this. I've changed the loadObjectList to just loadResult, assuming that they only have one subscription?
if ($user->id > 0 ) {
$db = & JFactory::getDBO();
$query = "SELEC" . "T b.expiry_date
from #__cbsubs_subscriptions as b
left join #__comprofiler as a on a.user_id = b.user_id
where b.user_id=" . (int)$user->id;
$db->setQuery( $query );
$result = $db->loadResult(); // prob in form 2010-08-03 00:41:21
$target_ts = strtotime($result);
$days_to_go = (int) (($target_ts - time()) / (24*60*60));
if ($days_to_go < 30) {
session_start();
$instance_name = "cbsubs_expiring";
if (!isset($_SESSION[$instance_name]) ||
$_SESSION[$instance_name] == false) {
$_SESSION[$instance_name] = true;
$target_date = date("d/m/Y",$target_ts);
$message = "Your membership expires on $target_date! Click here to renew."; // add a hyperlink
echo $message;
}
}
}
In this case we're just displaying some text in a module, rather than MetaMod pulling in another module. But you could still pull in another module by returning a module id after displaying the message.
I haven't tested this but it looks like you can code PHP, so at least this will get you started.
Best regards,
Stephen
Re: php + once-per-session cookie issue
Yes, when you use loadResult() then it will be a string. The original example returned an array. In the example I am assuming that there's only one subscription, so a single returned string is what I would expect.
Cheers,
Stephen
- Index
- » MetaMod
- » MetaMod General Support
- » php + once-per-session cookie issue
Board Info
- Board Stats:
- Total Topics:
- 1699
- Total Polls:
- 6
- Total Posts:
- 5967
- Total Posts Today:
- 2
- User Info:
- Total Users:
- 8021
- Newest User:
- shrutihassan193
- Members Online:
- 0
- Guests Online:
- 87
- 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