Capturing Session ID from URL in Joomla

Giarc86

Expert Member
Joined
May 28, 2008
Messages
1,243
Reaction score
4
Hi all,

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:

Code:
<?php
session_start();
$_SESSION['campaign']=$_GET['campaign'];
?>
Will this capture the session and will this work with Joomla as I know Joomla uses its own session ID's?

I haven't been able to test as I don't control the forms, so just wanting to make sure this is the correct way.

Is there a way to check what the current session ID is?

Thanks in advance.
 
Using the word session ID is a bit broad, session id of the php web server or joomla's session id ?
I'm not sure what your question is.

Code:
<?php
session_start();
$_SESSION['campaign']=$_GET['campaign'];
?>

This will store it as a session variable , and yes you will be able to call it from any page , depending on the session timeout period set on the server.



To put it like this. (Hope the reply will give you some direction)
There a 4 common ways to store a variable in php.

1.$MyValue = 'Helo World'
2.$_SESSION['MyValue']='Hello World'; //Like you have pointed out
3.setcookie("MyValue", "Hello world", time()+3600);
or you store it in a URL like you mentioned.
URL /?campaign=the_campaign_name
4.$_GET['campaign']; will be = to 'the_campaign_name '

Way 1:Wont follow you from page to page you have to store it in a cookie or URL or $_POST it to the next page.
Way 2:Will follow you for a specific period set by the admin of the server
Way 3:Will follow you because its a file on your PC and can be called anytime before the expire date
Way 4:Will follow you but you obviously must post it from page to page in the URL.

To get the session id from the php server.

start the session
then get the session

Code:
session_start();
$MySession = session_id();


Or rather
Code:
<?php
$MySession = session_id();
if(empty($MySession)) 
{
session_start();
$MySession = session_id();
}

echo 'My Current Session ID is:' . $MySession;


?>



http://php.net/manual/en/function.session-id.php

Cheers
 
Last edited:
Thank you very much for this! It makes a lot of sense.

I'm assuming way 3 will suit my needs as it needs to be stored as a file and then follow the user through the site.

It doesn't seem to be capturing the ID from the URL though.

A PHPSESSID is displaying: fv2h5qva3i6nhhqu8dalceb2h5 but not the campaign ID

I'm unsure if this:
Code:
<?php
session_start();
$_SESSION['campaign']=$_GET['campaign'];
?>

will capture the campaign from the URL.

Trying
Code:
<?php
$session =& JFactory::getSession();
$session->set( 'campaign' );

$session->get( 'campaign' );
?>

brings no luck as well.

I'll try see what the problem is.

Thanks very much.
 
Top
Sign up to the MyBroadband newsletter
X