session variables

Hi


I have a session variable called UserID in my website - i need to get that value into lectora to use within the elearning modules -


Is there any way that I can read a session variable into a variable within lectora?


Any guidance would be grately appreciated


thanks


Ian

Discussion (12)

Thanks for your replies..


Yes, I could do with some guidance if you dont mind - I'm fine with quite a bit of lectora but I have never used javascript in it, and to be honest done very little with javascript in any other way...



Any help would be appreciated..


Ian

OK - this should be fun. So as noted there are a couple ways you can go about this. The first is to append the user ID to the launch url. This means you would need to edit your site code. I'm not sure how your courses are launched but if it were a simple anchor tag it would look something like this:

Code:

Launch Course


We are just using PHP to output the session ID to the end of the launch URL.


Now in Lectora open the variable manager and make a new variable called "user_id"

If you want to have this variable be available on every page you can put an action at the course level with the following:

On Show

Target: user_id

Type: Set Equal to

Value: VAR(user_id)


All that does is sets the variable equal to itself, but it will also make that variable available on every page.


Now, to set our variable equal to the user id we are passing in you will need to add an external HTML object.

Name it whatever you want. For the type user "Custom DIV" and click on "Edit" and put this code in there:

Code:


That should do it and you should be able to use the lectora variable of user_id wherever you want.


If this solution won't work for you we can write a php script that you can put on your server whose whole purpose is to just return the session variable of the user id. Then, we can use an external HTML object in Lectora with AJAX or jQuery to call it and get the user id back so we can set it to a lectora variable and use it in there.


I know this is a lot - let me know if it helps.

You'll have to add some code to your website so the session variable is appended to the launch location of your course. Basically your URL to launch the course would look like: [url]http://mysite/mycourse/index.html?userid=datafromsession[/url]


Then, on the first page of your Lectora course you could use JavaScript to grab the data from the URL and set it to a Lectora variable for use in the course.


Let me know if that helps or if you need some code samples.

Hi


Thanks for all this - its great.. I will try it out later and see i f i can get it working.


Just a bit of background - i have a website which contains some learning modules. When a module is completed I have been using the submit variables action to pass the module information to a php script which picked up the session variable and wrote all the data into a database.


All works very well external to the Trust network. Internally, we have to paths out of the Trust network. One is working fine, but the other looses the session variable intermittently - i presume it may be something to do with timeout but not sure. Whilst our IT dept may be able to fix it, I am pretty sure that if i can pass the userID in an url parameter to the php script - along with the other information it will resolve the issue.


I'll let you know how I get on with the guide you have given - thanks very much for taking the time to help


Ian

The above solution is a good one. Just to provide an alternative, here's a suggestion. You can use JavaScript to issue a GET request to the server and get the UserID in response. That will probably require adding an extra file or an extra function to your website, but you won't have to mess with course launch URLs.

The site is written in php

What language is your website written in? PHP, Java, ASP, Ruby, etc... ?

@hem99004 60723 wrote:


If you want to have this variable be available on every page you can put an action at the course level with the following:

On Show

Target: user_id

Type: Set Equal to

Value: VAR(user_id)


All that does is sets the variable equal to itself, but it will also make that variable available on every page.

Again, a side note. You can assign any variable as "required variable" to your script and it'll be initialised everywhere where your script is. It's a cleaner and safer way to make sure your Lectora variables are accessible from JS.

Hi


Thanks again for the help.


I have tried your suggestion and it doesnt appear to be working..


The url i am using to start the module in the browser is:


http://www.nwaslearningzone.net/test/index.html?userID=10


I have made a one page test module.


At the top level I have the action to make the variable available to all pages

Underneath that, the html object with the javascript in

then a page with an on show event to display the user_id variable on the page.


The variable isnt receiving the url parameter for some reason.


Would this be because when the module is opened from the web page it is done so in a new window? Or have I done something wrong?


I have zipped up the module and attached it. If you could have a quick look it would be appreciated.

HI Guys I just tried the same thing but it does not work for me

On my modules that receive a userid via url parameter i have an opening page which is a welcome page - whenever anyone starts a module the first page that opens i call a flash page - this can contain anything such as objectives, and is only visited once - all the content comes after this page

On the page I have an action which is set to run on show..

It is a run javascript action and the content is

var tmp = window.location.search.substring(1);

var getUID = tmp.split("=");

VarUserID.set(getUID[1]);

undefined

Just tried this and its does not work for me. Please advice

Discussions have been disabled for this post