Jump to content
Jack_mcs

Auto Update Currencies

Recommended Posts

its the file session, nothing modified inside, no extra lines at the beginning or end.

I appreciate if you can have a look with me. thanks

sorry, but Im here because the cronjob email I received from the Auto update currency addon, output this an error.

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2008 osCommerce

  Released under the GNU General Public License
*/

  if ( (PHP_VERSION >= 4.3) && ((bool)ini_get('register_globals') == false) ) {
    @ini_set('session.bug_compat_42', 1);
    @ini_set('session.bug_compat_warn', 0);
  }

  if (STORE_SESSIONS == 'mysql') {

    function _sess_open($save_path, $session_name) {
      return true;
    }

    function _sess_close() {
      return true;
    }

    function _sess_read($key) {
  $value_query = tep_db_query("select value from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "'");
  $value = tep_db_fetch_array($value_query);

  if (isset($value['value'])) {
    return $value['value'];
  }

  return '';
}

    function _sess_write($key, $value) {
  $check_query = tep_db_query("select 1 from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "'");

  if ( tep_db_num_rows($check_query) > 0 ) {
    return tep_db_query("update " . TABLE_SESSIONS . " set expiry = '" . tep_db_input(time()) . "', value = '" . tep_db_input($value) . "' where sesskey = '" . tep_db_input($key) . "'");
  } else {
    return tep_db_query("insert into " . TABLE_SESSIONS . " values ('" . tep_db_input($key) . "', '" . tep_db_input(time()) . "', '" . tep_db_input($value) . "')");
  }
}

    function _sess_destroy($key) {
      return tep_db_query("delete from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "'");
    }

    function _sess_gc($maxlifetime) {
  return tep_db_query("delete from " . TABLE_SESSIONS . " where expiry < '" . (time() - $maxlifetime) . "'");
}

    session_set_save_handler('_sess_open', '_sess_close', '_sess_read', '_sess_write', '_sess_destroy', '_sess_gc');
  }

  function tep_session_start() {
  global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS;

  $sane_session_id = true;

  if ( isset($HTTP_GET_VARS[tep_session_name()]) ) {
    if ( (SESSION_FORCE_COOKIE_USE == 'True') || (preg_match('/^[a-zA-Z0-9,-]+$/', $HTTP_GET_VARS[tep_session_name()]) == false) ) {
      unset($HTTP_GET_VARS[tep_session_name()]);

      $sane_session_id = false;
    }
  }

  if ( isset($HTTP_POST_VARS[tep_session_name()]) ) {
    if ( (SESSION_FORCE_COOKIE_USE == 'True') || (preg_match('/^[a-zA-Z0-9,-]+$/', $HTTP_POST_VARS[tep_session_name()]) == false) ) {
      unset($HTTP_POST_VARS[tep_session_name()]);

      $sane_session_id = false;
    }
  }

  if ( isset($HTTP_COOKIE_VARS[tep_session_name()]) ) {
    if ( preg_match('/^[a-zA-Z0-9,-]+$/', $HTTP_COOKIE_VARS[tep_session_name()]) == false ) {
      $session_data = session_get_cookie_params();

      setcookie(tep_session_name(), '', time()-42000, $session_data['path'], $session_data['domain']);
      unset($HTTP_COOKIE_VARS[tep_session_name()]);

      $sane_session_id = false;
    }
  }

  if ($sane_session_id == false) {
  tep_redirect(tep_href_link(FILENAME_DEFAULT, '', 'SSL', false));
}

register_shutdown_function('session_write_close');

  return session_start();
}

  function tep_session_register($variable) {
    if (PHP_VERSION < 4.3) {
      return session_register($variable);
    } else {
      if (!isset($GLOBALS[$variable])) {
        $GLOBALS[$variable] = null;
      }

      $_SESSION[$variable] =& $GLOBALS[$variable];
    }

    return false;
  }
	
  function tep_session_is_registered($variable) {
    if (PHP_VERSION < 4.3) {
      return session_is_registered($variable);
    } else {
      return isset($_SESSION) && array_key_exists($variable, $_SESSION);
    }
  }

  function tep_session_unregister($variable) {
    if (PHP_VERSION < 4.3) {
      return session_unregister($variable);
    } else {
      unset($_SESSION[$variable]);
    }
  }

  function tep_session_id($sessid = '') {
    if ($sessid != '') {
      return session_id($sessid);
    } else {
      return session_id();
    }
  }

  function tep_session_name($name = '') {
    if ($name != '') {
      return session_name($name);
    } else {
      return session_name();
    }
  }

  function tep_session_close() {
    if (PHP_VERSION >= '4.0.4') {
      return session_write_close();
    } elseif (function_exists('session_close')) {
      return session_close();
    }
  }

  function tep_session_destroy() {
  global $HTTP_COOKIE_VARS;

  if ( isset($HTTP_COOKIE_VARS[tep_session_name()]) ) {
    $session_data = session_get_cookie_params();

    setcookie(tep_session_name(), '', time()-42000, $session_data['path'], $session_data['domain']);
    unset($HTTP_COOKIE_VARS[tep_session_name()]);
  }

  return session_destroy();
}

  function tep_session_save_path($path = '') {
    if ($path != '') {
      return session_save_path($path);
    } else {
      return session_save_path();
    }
  }
?>

 

Edited by Psytanium

Share this post


Link to post
Share on other sites

If the file is exactly as shown, then there isn't anything wrong with it. If the only problem is when this script is ran as a cron job I don't know what it might be. There is an alternative method provided if you can't get the cron job to work. Other than that, it would require troubleshooting to see what the issue is.

Share this post


Link to post
Share on other sites

I checked on all the files inside functions, includes, classes. in both admin and front, nothing wrong with the beginning and ending.

I tried to launch the file directly from the browser and to use the second method. still currency didn't changed.

I will try more troubleshooting, if you have some ideas where to look let me know. thanks

Share this post


Link to post
Share on other sites

The currency not being updated is a different problem than the script not running. That might be due to not having the "fixer" update installed. See the previous pages for details about this.

Share this post


Link to post
Share on other sites

The fixer modification already applied, I did make sure.

The manual currency update is working

Latest version of the addon is installed, January 2017.

All the website is running fine, no errors, just the addon return this error and not updating currencies.  :sad: I don't even know where to look.

Share this post


Link to post
Share on other sites

It might be that you may be using an older version of oscommerce and the latest version of this addon and they are not compatible.  Or maybe your php version has something to do with it. Unfortunately, it isn't something I can solve in a support thread since it is specific, apparently, to your shop and would require troubleshooting to find the problem.

Share this post


Link to post
Share on other sites
On 8/29/2017 at 1:30 PM, Psytanium said:

what could be the reason ?


<br />
<b>Warning</b>:  session_start(): Cannot send session cookie - headers already sent in <b>/home/user/public_html/admin/includes/functions/sessions.php</b> on line <b>98</b><br />
<br />
<b>Warning</b>:  session_start(): Cannot send session cache limiter - headers already sent in <b>/home/user/public_html/admin/includes/functions/sessions.php</b> on line <b>98</b><br />

 

Something at sessions.php on line 98 sent text or tags to the browser (the very first text; it could be as little as a blank or a carriage return). That triggers the server to send all the HTTP "headers" it has at the moment. Once those headers are sent, no more can normally be sent, and you get those errors when the osC code attempts to set more headers to send. You need to look at line 98 and vicinity, and see what got sent. It could be a blank or empty line after the very last ?> (simply go in with an editor and clean out any junk at the end). It could be an error message from the code. it could even be output from a hack. Look in the browser "Show Page Source" to see what comes before the on-screen error message (there ought to be some text there). Once you clear it up, both the error messages you got should disappear. It's not necessary to try removing the ?> and everything following, unless you absolutely can't find the cause. And be careful when editing PHP files not to leave garbage behind (you may have to change editors if yours leaves ^Z or something behind).

Share this post


Link to post
Share on other sites
On 8/29/2017 at 8:30 PM, Psytanium said:

Hello Jack,

what could be the reason ?


<br />
<b>Warning</b>:  session_start(): Cannot send session cookie - headers already sent in <b>/home/user/public_html/admin/includes/functions/sessions.php</b> on line <b>98</b><br />
<br />
<b>Warning</b>:  session_start(): Cannot send session cache limiter - headers already sent in <b>/home/user/public_html/admin/includes/functions/sessions.php</b> on line <b>98</b><br />

thank :)

I don't know why the Ultimate SEO URL 5 addon is preventing the admin/auto_update_currencies.php form running, but when I moved the file auto_update_currencies.php to home directory catalog, it's running and updating the currencies as it should. I had to include the functions inside the file.

Share this post


Link to post
Share on other sites

This addon should work regardless of what you do with SEO 5. It sounds like you have something wrong with the installation. Those two addons don't have anything in common. SEO 5 runs on the shop side while this one runs on the admin side. Both do edit the general.php file in admin so you may have made a mistake there.

Share this post


Link to post
Share on other sites

Don't forget that running PHP code in cron (system command line) is different from running it in the web server (via HTTP). You are not in the same environment, and may have different path settings, environmental settings, and even a different version of PHP. In general, if using cron, you want to make sure everything (paths, settings, etc.) are explicitly spelled out.

Share this post


Link to post
Share on other sites

Ok, the manual of the auto-update-currency addons says:

Step 3c: Go to admin->Configuration->My Store and set the Auto Update Currency
         setting to an hour. The script will run before that hour eahc day
         providing someone is in admin prior to it.

But i dont see the Auto Update Currency
         setting option in admin->Configuration->My Store

Share this post


Link to post
Share on other sites

Step 3 is only for when cron won't work. If you use step 3, you have to apply the database change mentioned

Share this post


Link to post
Share on other sites
2 minutes ago, Jack_mcs said:

Step 3 is only for when cron won't work. If you use step 3, you have to apply the database change mentioned

Yes, cron wont work because of my hosting company. Running the database change is step 3a which i did; i ran the sql file which inserted the row into the database successfully and did everything else before (except step 2) 

Share this post


Link to post
Share on other sites

Does your host actually not let you run cron (on a Linux server), or do they restrict the kinds of things you can run, such as PHP scripts using 'php'? Mine does the latter, but they allow using cURL to run PHP scripts.

Share this post


Link to post
Share on other sites
5 hours ago, alex121121 said:

Running the database change is step 3a which i did

If you did that and it didn't fail, the setting has to be in your database. I've seen some templates that sort the configuration settings into different sections so that there is more than one configuration section in admin. Short of something like that, I can't even guess at what went wrong. You can search the database for AUTO_UPDATE_CURRENCY_BEFORE, which that sql change adds. It has to be there somewhere if there were not any failures.

Share this post


Link to post
Share on other sites

admin->Configuration->My Store and set the Auto Update Currency

7 hours ago, Jack_mcs said:

You can search the database

yea, i did that, and it turns out i had also one test database and when i selected the original database and inserted the code successfully again, the auto update currency appeared. Thanks. At 9:30, i entered 10 (o'clock) in the auto update currency option and now at 10:15, it didnt update yet. Was it supposed to? I dont really understand what the manual means by: "The script will run before that hour eahc day
         providing someone is in admin prior to it."  

Share this post


Link to post
Share on other sites
8 hours ago, MrPhil said:

Does your host actually not let you run cron

Well, officially they do but when i made a cron job in their Cpanel, it triggered some kind of auto immune reaction in their server which prevented me to log into my osCommerce admin for 2 weeks. i had to open like 6 tickets until it was finally resolved and each ticket makes you wait like 2 days. It turned out to be some security protocol which happens on shared servers when people try cron job for the first time without it being authorized by the higher level host admins or something. I deleted the cron job and dont wanna have anything to do with it anymore.  

Share this post


Link to post
Share on other sites
2 hours ago, alex121121 said:

I dont really understand what the manual means by: "The script will run before that hour eahc day
         providing someone is in admin prior to it."  

The code compares the current hour to what you have in the setting. If you have it set to 10 and you never login to your admin before 10, the script will never run. Also, it only runs when you are on the index,php page of admin. So sometime before 10 go to ...com/admin/index.php and it should run.

You can run it manually by going to ...com/admin/auto_update_currencies.php If that works, then it is a time or page issue as described. If it doesn't, then it is probably due to the links for currencies. Try updating the currencies manually in the currencies section of admin to see if the code will do it.

Share this post


Link to post
Share on other sites
22 hours ago, Jack_mcs said:

If that works, then it is a time or page issue as described

Updating manually works perfect as before. But auto update still doesnt work, if its page issue, do you know what i could do?

Share this post


Link to post
Share on other sites

If the code only looks at the time of day, and doesn't keep track of the day on which it was last run, it's not very good code. Anyway, if you can't run a proper "cron" job, look at "poor man's cron" examples that do track when the last time something was run was, and kick off the run if enough time has passed. Such code would be started from some place in osC such as application_top.php. I think there may be a poor man's cron in one of the mass mailing add-ons, where you don't want to dump an avalanche of emails on the system, but just dribble out a few at a time, then wait for the next run of osC that's a few minutes later. I don't know if anyone has generalized a PMC to run arbitrary modules at arbitrary times/dates, but that would be a great feature for osC.

Perhaps you would be better off if you worked with your host to understand what their limitations are on cron jobs. It's understandable that they want to keep out-of-control scripts off their servers, but cron is a necessary part of any non-trivial website. You got burned once by not understanding what they allowed, but that doesn't mean you can't craft a cron job that they will allow.

Share this post


Link to post
Share on other sites
6 hours ago, alex121121 said:

But auto update still doesnt work, if its page issue, do you know what i could do?

First, check the php version you are using in admin->tools->Server Info, It has to be 5.3 or above. If it is, edit the admin/auto_update_currencies.php file and change

  if (! isset($_SERVER['HTTP_USER_AGENT'])) { //ran by cron 
      require('includes/application_top.php');
  }

to

      require('includes/application_top.php');

Does that make a difference?

Share this post


Link to post
Share on other sites
On 6/30/2019 at 5:15 PM, Jack_mcs said:

Does that make a difference?

Sorry, i was unavailable for some time, i have php version 7.1.14 (Zend: 3.1.0) so that should be allright. I changed the code and it does not seem to make a difference. Should i change it back?

   

Share this post


Link to post
Share on other sites

Check your cron job and make sure there isn't anything after the the .php and that your email address is set for cron. Then run it and you should get a message from cron showing why it failed. 

The previous code change should be changed back but you may want to see what the message says both ways.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×