Reputation: 499
I am trying to capture a session ID from a URL so that the ID will follow a user throughout the site and then get captured when they fill in a form.
The URL will look something like this.
http://www.mysite.co.za/?campaign=the_campaign_name
Then I inserted this code into the top of my Joomla template file:
session_start();
$_SESSION['campaign']=$_GET['campaign'];
Will this capture the session (the_campaign_name) and will this work with Joomla as I know Joomla uses its own session ID's?
When I check the sessions I just get a PHPSESSID showing its session.
Thanks in advance.
Upvotes: 0
Views: 2214
Reputation: 499
This seems to have worked for me, if this helps anyone:
<?php
if (isset($_GET['campaign'])) {
$campaign = $_GET['campaign'];
}
setcookie('CampaignName', $campaign);
?>
Not sure if it's even the correct way but it worked for me on Joomla.
Upvotes: 3
Reputation: 3696
Since you are using Joomla, why not make use of the Joomla framework?
To set:
JFactory::getSession()->set('campaign', JRequest::getVar('campaign'), $optional_namespace);
To get:
JFactory::getSession()->get('campaign', $optional_default_value, $optional_namespace);
Upvotes: 0
Reputation: 25755
yes it should work, joomla is PHP. and what you are trying to do is PHP, if you want to check all the created session variable then try
session_start();
var_dump($_SESSION);
Update:
it seems joomla stores the session variables in database, according to the documentation you need to set and access session variable in joomla like this.
to set session variable
$session =& JFactory::getSession();
$session->set('campaign', $_GET['campaign']);
to get session variable
$session =& JFactory::getSession();
echo $session->get('campaign');
it seems joomla upon initialization destroys the regular session variable for some security reason they say, here is the link from joomla documentation to help you http://docs.joomla.org/How_to_access_session_variables_set_by_an_external_script
hope this helps. and always remember to sanitize user input with proper validation. before using it.
Upvotes: 0