Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Using session variables outside of osCommerce


camNZ

Recommended Posts

Hello,

 

As part of my store, I generate a session variable outside of the catalog root:

 

e.g: in root/test.php I have

 

session_register("storeXXXX");

$storeXXXX= $myVariable; //which comes from a URL

 

Now I want to access and utilise this $storeXXXX from a page in root/catalog/includes/application_top.php

 

However, it always appears blank. I have tested this on a page outside of the root/catalog and it works fine, the problem only seems to occur when I try and use it within the catalog structure.

 

Can anyone shed any light or offer any suggestions?

 

Thanks

Campbell

Link to comment
Share on other sites

you should copy and use one of the osc catalog files into the root of your store. Then simply change the path of the script inside the catalog, before the application_top inclusion and use the tep_session_register osc functions.

Link to comment
Share on other sites

you should copy and use one of the osc catalog files into the root of your store. Then simply change the path of the script inside the catalog, before the application_top inclusion and use the tep_session_register osc functions.

 

Thanks for that, so just to be clear here is my file which is found at root/catalog/loader.php

 

I send a URL with parameter "$storenumber" to this file. I would like to create a session variable "$storeName" or constant before I get to the application_top.php because I want to use this variable in the "inlcude configure.php" line.

 

 

<?php

//this loads the correct store

 

require('includes/functions/sessions.php');

 

//start the session

tep_session_start();

$session_started = true;

 

session_register("storeName");

$storeName= $storenumber;

 

header("Location: index.php");

?>

 

Using the oscommerce tep_session function, how do I register and use a variable of my own definition?

 

Thanks,

Campbell

Link to comment
Share on other sites

No, because the session is not available at that time. It has to come after the configure.php is parsed. The way I would do this is to simply use the application_top as is let it create the sessions and simply include it with the root file and just change the directory and the use the regular functions

		if (!tep_session_is_registered('test_var') )
	  tep_session_register('test_var');
	$test_var = 10;

Link to comment
Share on other sites

Thank you.

 

My problem is this:

 

Everytime, the application_top loads and gets to the line:

 

// include server parameters

require(' ***path to configure dir*** /configure.php');

 

I want to include a session variable as my "***path to configure***"

 

Because the session.php includes come after the configure include, I cant really use it. Or can I?

 

Thanks for your help.

Campbell

Link to comment
Share on other sites

can you tell me why you need a different configure.php based on session (meaning which part of the configure.php you're interested on)? Then I may understand what field of the configure.php has to be dynamic and see what changes you need to do.

Link to comment
Share on other sites

i have 2 shops (2 urls) utilizing the same catalog/ code.

 

shop 1 has a url of www.shop1.com which sends the user to the catalog but needs to connect with a different database etc.. then shop2 has www.shop2.com which also connects with a different database.

 

therefore when we enter the first url, i want to initialise the shop1 session variable, go to the catalog and when the application_top is included it will know to get the right configure.php file

 

thanks, i hope this makes it more clear

Link to comment
Share on other sites

Ok you may want to take a look how the multi-store contribution works. Perhaps it's way too complicated at this point to make changes to existing stores so you could do this:

 

1. Change the sessions to be stored in files.

2. Check also this contribution how it connects to a different database (phpbb_forum_external.php)

http://www.oscommerce.com/community/contributions,3600

 

basically it defines another set of database functions and definitions

3. Leave the beginning of application_top.php as is up to a point like:

// set SID once, even if empty
 $SID = (defined('SID') ? SID : '');

 

At that point your session is generated and is stored in a file. Just after that you could check the session and switch databases.

  tep_db_close();
 tep_db_connect2() or die('Unable to connect to database server2!');

 

Basically you disconnect from the first and connect to the 2nd. One of the challenges will be to integrate both sets of database functions into one but is doable. (or implement wrappers to use the 2nd database)

Link to comment
Share on other sites

Thanks for your time and help.

 

I managed to get all the session code above the "require configure.php" include in application_top. So in theory i can use the tep_session to store a session variable for "shopNumber" and use it in the "require configure location.

 

Do you know how I could create a new session variable using tep_session?

 

And then how can I retrieve it?

 

Thanks,

Campbell

Link to comment
Share on other sites

thanks.

 

i think i get the drift. so to create a new session variable called 'myVar'

 

tep_session_register('myVar');

$myVar = 100;

 

Then to retrive it i would do this:

$myVarValue = tep_session_register('myVar');

 

Thanks,

Campbell

Link to comment
Share on other sites

thanks.

 

i think i get the drift. so to create a new session variable called 'myVar'

 

tep_session_register('myVar');

$myVar = 100;

 

Then to retrive it i would do this:

$myVarValue = tep_session_register('myVar');

 

Thanks,

Campbell

no, the variable already has a value. All you need to do is check it. once you register the var it becomes a global variable.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...