Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Sessions on Home page problem


Guest

Recommended Posts

I am having a small problem with sessions. I recently discovered some of my links were not using tep_href_link. I fixed these but am still having one issue.

 

For some reason, cookie based sessions are not working for me and I cannot have our site down for long enough to figure it out. So, for now, I am passing the sessions around in the url.

 

When a user comes to my site, they do not have a session id (or at least it does not show up in the url of the page). If they click on a link and go and add products to the site everything works fine. However, if they use the back button and go all the way back to the home page where no osCsid is set in the title they lose their session.

 

Is there a way to have this set when they come to the site?

Link to comment
Share on other sites

Have you installed any contributions that affected includes/application_top.php or includes/functions/html_output.php?

 

I've installed so many of these carts, I forget for sure. However, the only mods that are installed to my recollection are administrative other than the gift certificate module (gvcc).

Link to comment
Share on other sites

Install my debug contribution (should take 3 minutes) and we'll be able to get a better method of checking the session and cookie contents.

 

Let me know when you get it installed and also provide me an URL.

Link to comment
Share on other sites

Install my debug contribution (should take 3 minutes) and we'll be able to get a better method of checking the session and cookie contents.

 

Let me know when you get it installed and also provide me an URL.

 

 

Thanks for the help, chemo. I have installed your contribution and enabled it. Please take a look at: http://www.tigerrags.com and let me know what you think.

 

If you click on one of the products on the front page and then add it to your cart everything looks okay. If you then use the back button in your browser to go back to the home page the cart dissappears when you get there.

 

I noticed where it is setting the session on the front page. It is just not finding it when we go back to the home page.

Link to comment
Share on other sites

Shoot...sorry about this but a few things need to be changed to get the output we need.

 

In includes/performance.php find this code (basically all of it):

    if (DISPLAY_PAGE_PARSE_TIME == 'true') {
   $time_start = explode(' ', PAGE_PARSE_START_TIME);
   $time_end = explode(' ', microtime());
   $parse_time = number_format(($time_end[1] + $time_end[0] - ($time_start[1] + $time_start[0])), 3);
   echo '<div align="center"><span class="smallText">Current Parse Time: <b>' . $parse_time . ' s</b> with <b>'.sizeof($debug['QUERIES']).' queries</b></span></div>';
if ($_REQUEST['output'] == '0') $_SESSION['output'] = '0';
if ($_REQUEST['output'] == '1' || $_SESSION['output'] == '1')
 {
	 $_SESSION['output'] = '1';
	 echo '<pre>';
	 print_r($debug);
	 echo '</pre>';
 } # END if request
   }
unset($debug);

And change it to this:

    if (DISPLAY_PAGE_PARSE_TIME == 'true') {
   $time_start = explode(' ', PAGE_PARSE_START_TIME);
   $time_end = explode(' ', microtime());
   $parse_time = number_format(($time_end[1] + $time_end[0] - ($time_start[1] + $time_start[0])), 3);
   echo '<div align="center"><span class="smallText">Current Parse Time: <b>' . $parse_time . ' s</b> with <b>'.sizeof($debug['QUERIES']).' queries</b></span></div>';
if ($_REQUEST['output'] == '0') $_SESSION['output'] = '0';
if ($_REQUEST['output'] == '1' || $_SESSION['output'] == '1')
 {
	 $_SESSION['output'] = '1';
	 echo '<pre><b>COOKIE INFO:</b><br>';
	 print_r($_COOKIE).'</pre>';
	 echo '<hr>';
	 echo '<pre><b>SESSION INFO:</b><br>';
	 print_r($_SESSION).'</pre>'; 	 
	 echo '<hr>';
	 echo '<pre>';
	 print_r($debug);
	 echo '</pre>';
 } # END if request
   }
unset($debug);

The change adds the cookie and session info to the debug output. I forgot the contribution only outputs the query info. My bad.

 

Also, in includes/application_bottom.php find this code:

tep_session_close();

And move it above this:

  if ( (GZIP_COMPRESSION == 'true') && ($ext_zlib_loaded == true) && ($ini_zlib_output_compression < 1) ) {
   if ( (PHP_VERSION < '4.0.4') && (PHP_VERSION >= '4') ) {
     tep_gzip_output(GZIP_LEVEL);
   }
 }

This change makes sure the session is not closed until after we need to output the contents.

 

Make these changes and we'll give it another go...once again, my sincere apologies.

 

Bobby

Link to comment
Share on other sites

Shoot...sorry about this but a few things need to be changed to get the output we need.

 

In includes/performance.php find this code (basically all of it):

 ? ?if (DISPLAY_PAGE_PARSE_TIME == 'true') {
? ?$time_start = explode(' ', PAGE_PARSE_START_TIME);
? ?$time_end = explode(' ', microtime());
? ?$parse_time = number_format(($time_end[1] + $time_end[0] - ($time_start[1] + $time_start[0])), 3);
? ?echo '<div align="center"><span class="smallText">Current Parse Time: <b>' . $parse_time . ' s</b> with <b>'.sizeof($debug['QUERIES']).' queries</b></span></div>';
if ($_REQUEST['output'] == '0') $_SESSION['output'] = '0';
if ($_REQUEST['output'] == '1' || $_SESSION['output'] == '1')
?{
?	$_SESSION['output'] = '1';
?	echo '<pre>';
?	print_r($debug);
?	echo '</pre>';
?} # END if request
? ?}
unset($debug);

And change it to this:

 ? ?if (DISPLAY_PAGE_PARSE_TIME == 'true') {
? ?$time_start = explode(' ', PAGE_PARSE_START_TIME);
? ?$time_end = explode(' ', microtime());
? ?$parse_time = number_format(($time_end[1] + $time_end[0] - ($time_start[1] + $time_start[0])), 3);
? ?echo '<div align="center"><span class="smallText">Current Parse Time: <b>' . $parse_time . ' s</b> with <b>'.sizeof($debug['QUERIES']).' queries</b></span></div>';
if ($_REQUEST['output'] == '0') $_SESSION['output'] = '0';
if ($_REQUEST['output'] == '1' || $_SESSION['output'] == '1')
?{
?	$_SESSION['output'] = '1';
?	echo '<pre><b>COOKIE INFO:</b><br>';
?	print_r($_COOKIE).'</pre>';
?	echo '<hr>';
?	echo '<pre><b>SESSION INFO:</b><br>';
?	print_r($_SESSION).'</pre>'; ?	
?	echo '<hr>';
?	echo '<pre>';
?	print_r($debug);
?	echo '</pre>';
?} # END if request
? ?}
unset($debug);

The change adds the cookie and session info to the debug output.  I forgot the contribution only outputs the query info.  My bad.

 

Also, in includes/application_bottom.php find this code:

tep_session_close();

And move it above this:

 ?if ( (GZIP_COMPRESSION == 'true') && ($ext_zlib_loaded == true) && ($ini_zlib_output_compression < 1) ) {
? ?if ( (PHP_VERSION < '4.0.4') && (PHP_VERSION >= '4') ) {
? ? ?tep_gzip_output(GZIP_LEVEL);
? ?}
?}

This change makes sure the session is not closed until after we need to output the contents.

 

Make these changes and we'll give it another go...once again, my sincere apologies.

 

Bobby

 

done

Link to comment
Share on other sites

It is verified...the cookie system is not functional.

 

1. In includes/configure.php copy the COOKIE_DOMAIN definitions.

2. In application_top.php copy the relevant portions pertaining to cookies and sessions.

Link to comment
Share on other sites

It is verified...the cookie system is not functional.

 

1. In includes/configure.php copy the COOKIE_DOMAIN definitions.

2. In application_top.php copy the relevant portions pertaining to cookies and sessions.

 

If you need more, let me know.

 

configure.php:

 

define('HTTP_COOKIE_DOMAIN', '.tigerags.com');
 define('HTTPS_COOKIE_DOMAIN', '.tigerrags.com');

 

 

What I think is the relevant session code from application_top:

// check if sessions are supported, otherwise use the php3 compatible session class
 if (!function_exists('session_start')) {
   define('PHP_SESSION_NAME', 'osCsid');
   define('PHP_SESSION_PATH', $cookie_path);
   define('PHP_SESSION_DOMAIN', $cookie_domain);
   define('PHP_SESSION_SAVE_PATH', SESSION_WRITE_DIRECTORY);

   include(DIR_WS_CLASSES . 'sessions.php');
 }

// define how the session functions will be used
 require(DIR_WS_FUNCTIONS . 'sessions.php');

// set the session name and save path
 tep_session_name('osCsid');
 tep_session_save_path(SESSION_WRITE_DIRECTORY);

// set the session cookie parameters
  if (function_exists('session_set_cookie_params')) {
   session_set_cookie_params(0, $cookie_path, $cookie_domain);
 } elseif (function_exists('ini_set')) {
   ini_set('session.cookie_lifetime', '0');
   ini_set('session.cookie_path', $cookie_path);
   ini_set('session.cookie_domain', $cookie_domain);
 }

// set the session ID if it exists
  if (isset($HTTP_POST_VARS[tep_session_name()])) {
    tep_session_id($HTTP_POST_VARS[tep_session_name()]);
  } elseif ( ($request_type == 'SSL') && isset($HTTP_GET_VARS[tep_session_name()]) ) {
    tep_session_id($HTTP_GET_VARS[tep_session_name()]);
  }

// start the session
 $session_started = false;
 if (SESSION_FORCE_COOKIE_USE == 'True') {
   tep_setcookie('cookie_test', 'please_accept_for_session', time()+60*60*24*30, $cookie_path, $cookie_domain);

   if (isset($HTTP_COOKIE_VARS['cookie_test'])) {
     tep_session_start();
     $session_started = true;
   }
 } elseif (SESSION_BLOCK_SPIDERS == 'True') {
   $user_agent = strtolower(getenv('HTTP_USER_AGENT'));
   $spider_flag = false;

   if (tep_not_null($user_agent)) {
     $spiders = file(DIR_WS_INCLUDES . 'spiders.txt');

     for ($i=0, $n=sizeof($spiders); $i<$n; $i++) {
       if (tep_not_null($spiders[$i])) {
         if (is_integer(strpos($user_agent, trim($spiders[$i])))) {
           $spider_flag = true;
           break;
         }
       }
     }
   }

   if ($spider_flag == false) {
     tep_session_start();
     $session_started = true;
   }
 } else {
   tep_session_start();
   $session_started = true;
 }

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

Link to comment
Share on other sites

I too am having a cookie problem. I added the debug contrib like you asked.

 

 

I will PM you the link if you don't mind looking at it.

// define the project version
define('PROJECT_VERSION', 'osCommerce 2.2-MS2');

Link to comment
Share on other sites

  • 2 weeks later...

Can someone help me with my cookie issue as well?

 

It is verified...the cookie system is not functional.

 

1. In includes/configure.php copy the COOKIE_DOMAIN definitions.

2. In application_top.php copy the relevant portions pertaining to cookies and sessions.

 

 ?define('HTTP_COOKIE_DOMAIN', '.eet-wizdom.net');
?define('HTTPS_COOKIE_DOMAIN', '.eet-wizdom.net');
?define('HTTP_COOKIE_PATH', '/shop');
?define('HTTPS_COOKIE_PATH', '/shop');

 

// check if sessions are supported, otherwise use the php3 compatible session class
?if (!function_exists('session_start')) {
? ?define('PHP_SESSION_NAME', 'osCsid');
? ?define('PHP_SESSION_PATH', $cookie_path);
? ?define('PHP_SESSION_DOMAIN', $cookie_domain);
? ?define('PHP_SESSION_SAVE_PATH', SESSION_WRITE_DIRECTORY);

? ?include(DIR_WS_CLASSES . 'sessions.php');
?}

// define how the session functions will be used
?require(DIR_WS_FUNCTIONS . 'sessions.php');

// set the session name and save path
?tep_session_name('osCsid');
?tep_session_save_path(SESSION_WRITE_DIRECTORY);

// set the session cookie parameters
? if (function_exists('session_set_cookie_params')) {
? ?session_set_cookie_params(0, $cookie_path, $cookie_domain);
?} elseif (function_exists('ini_set')) {
? ?ini_set('session.cookie_lifetime', '0');
? ?ini_set('session.cookie_path', $cookie_path);
? ?ini_set('session.cookie_domain', $cookie_domain);
?}

// set the session ID if it exists
? if (isset($HTTP_POST_VARS[tep_session_name()])) {
? ? tep_session_id($HTTP_POST_VARS[tep_session_name()]);
? } elseif ( ($request_type == 'SSL') && isset($HTTP_GET_VARS[tep_session_name()]) ) {
? ? tep_session_id($HTTP_GET_VARS[tep_session_name()]);
? }

// start the session
?$session_started = false;
?if (SESSION_FORCE_COOKIE_USE == 'True') {
? ?tep_setcookie('cookie_test', 'please_accept_for_session', time()+60*60*24*30, $cookie_path, $cookie_domain);

? ?if (isset($HTTP_COOKIE_VARS['cookie_test'])) {
? ? ?tep_session_start();
? ? ?$session_started = true;
? ?}
?} elseif (SESSION_BLOCK_SPIDERS == 'True') {
? ?$user_agent = strtolower(getenv('HTTP_USER_AGENT'));
? ?$spider_flag = false;

? ?if (tep_not_null($user_agent)) {
? ? ?$spiders = file(DIR_WS_INCLUDES . 'spiders.txt');

? ? ?for ($i=0, $n=sizeof($spiders); $i<$n; $i++) {
? ? ? ?if (tep_not_null($spiders[$i])) {
? ? ? ? ?if (is_integer(strpos($user_agent, trim($spiders[$i])))) {
? ? ? ? ? ?$spider_flag = true;
? ? ? ? ? ?break;
? ? ? ? ?}
? ? ? ?}
? ? ?}
? ?}

? ?if ($spider_flag == false) {
? ? ?tep_session_start();
? ? ?$session_started = true;
? ?}
?} else {
? ?tep_session_start();
? ?$session_started = true;
?}

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

// define the project version
define('PROJECT_VERSION', 'osCommerce 2.2-MS2');

Link to comment
Share on other sites

  • 4 months later...

Hello All,

 

I'm adding some contrib on my test site (locally) on a mac os x. Now all of the sudden my sessions do not work at all. I can not put any items in the store nor does it allow log ins.

 

From reading the forums, it seems to be some problem with my store configuration but I no longer have any old versions of my local store so I do not know what I had to get it to work.

 

My public site works fine. The store on my local site is located at the URL http://127.0.0.1/catalog or http://localhost/catalog

 

Assuming the config file is the problem, what should I put in the COOKIE variables in the config file?

 

I've tried running the installer program again to see if it would get the correct values but it doesn't.

 

Thanks in advance for checking this out...If you need additional details let me know.

Link to comment
Share on other sites

Okay, I found the problem. :rolleyes:

 

It was all in my browser options. It seems at some point I had blocked 127.0.0.1 in the cookie settings. I've seen other people have this problem but I didn't realize it applied to me until I read a bug report on this site and someone had my problem with IE (I'm using Firefox)

 

I hope this helps someone with a similar problem. I glad it was not in the code or anything. I didn't want to have to uninstall any contributions.

 

With this block none of my sessions were starting.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...