Zen Cart Logo
Forums / General Questions / Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

Views: 5,337

Results 1 to 20 of 28
4 Oct 2012, 5:37 PM
#1
webmistressm avatar

webmistressm

New Zenner

Join Date:
Jan 2010
Location:
SoCal
Posts:
47
Plugin Contributions:
0

Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

My zencart store appears to be having a problem since upgrading to 1.5.1 (from 1.5.0), during the time when someone adds a product to the cart. They get the Error 500 or just a blank page when clicking "add to cart".

My debug log issued me the following:
[04-Oct-2012 09:59:28] PHP Fatal error: Call to undefined function zen_create_random_value() in /hsphere/local/home/user/prettygirlygirl.com/includes/classes/shopping_cart.php on line 1295

I used the following page to find out more where the zen_create_random_value is called and/or referenced
http://phpxref.com/xref/zencart/_functions/zen_create_random_value.html

Of the 2 files listed here that are believed to define the zen_create_random_value function, the functions_general.php (in /includes/functions/) is the one where zen_create_random_value seems to be absent. I did a check in the 1.5.0 site files to check for it there and there it was. On lines 614 to 634 of /includes/functions/functions_general.php (of the 1.5.0 version of Zencart), it reads:

  function zen_create_random_value($length, $type = 'mixed') {
    if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) return false;

    $rand_value = '';
    while (strlen($rand_value) < $length) {
      if ($type == 'digits') {
        $char = zen_rand(0,9);
      } else {
        $char = chr(zen_rand(0,255));
      }
      if ($type == 'mixed') {
        if (preg_match('/^[a-z0-9]$/i', $char)) $rand_value .= $char;
      } elseif ($type == 'chars') {
        if (preg_match('/^[a-z]$/i', $char)) $rand_value .= $char;
      } elseif ($type == 'digits') {
        if (preg_match('/^[0-9]$/', $char)) $rand_value .= $char;
      }
    }

    return $rand_value;
  }

I could not find anyone on here who is having this problem in 1.5.1 so I figured I would ask here. When I "add to cart" and get the blank page, I can sometimes reload the page and then I am taken to the shopping carts contents page. I clicked "checkout" and did not get a blank page again but I have not tried to complete the checkout process. On the shopping carts content page, any attempt to change the quantity and press the refresh button next to it also results in this blank page.

4 Oct 2012, 5:49 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,081
Plugin Contributions:
56

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

That function was moved to /includes/functions/password_funcs.php in v1.5.1 ... and removed from functions_general.php at the same time. Perhaps your 1.5.1 upgrade did not include the password_funcs.php file?

4 Oct 2012, 5:58 PM
#3
webmistressm avatar

webmistressm

New Zenner

Join Date:
Jan 2010
Location:
SoCal
Posts:
47
Plugin Contributions:
0

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

Hmm... just checked and that file is there (as stated in my original post). The definition of that function is on lines 50 to 86:

function zen_create_random_value($length, $type = 'mixed')
{
  if (($type != 'mixed') && ($type != 'chars') && ($type != 'digits'))
    return false;

  $rand_value = '';
  while (strlen($rand_value) < $length)
  {
    if ($type == 'digits')
    {
      $char = zen_rand(0, 9);
    } else
    {
      $char = chr(zen_rand(0, 255));
    }
    if ($type == 'mixed')
    {
      if (preg_match('/^[a-z0-9]$/i', $char))
        $rand_value .= $char;
    } elseif ($type == 'chars')
    {
      if (preg_match('/^[a-z]$/i', $char))
        $rand_value .= $char;
    } elseif ($type == 'digits')
    {
      if (preg_match('/^[0-9]$/', $char))
        $rand_value .= $char;
    }
  }
  
  if ($type == 'mixed' && !preg_match('/^(?=.*[\w]+.*)(?=.*[\d]+.*)[\d\w]{' . $length . ',}$/', $rand_value))
  {
    $rand_value .= zen_rand(0, 9);
  }

  return $rand_value;
}
4 Oct 2012, 6:23 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

How EXACTLY is your site different from a brand new uncustomized fresh install of v1.5.1?
Please click Reply below and answer all the questions in the Posting Tips section.

4 Oct 2012, 6:25 PM
#5
webmistressm avatar

webmistressm

New Zenner

Join Date:
Jan 2010
Location:
SoCal
Posts:
47
Plugin Contributions:
0

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

If you are speaking about actual add-ons and such....there is only one that I have--CEON URI Mapping. Turning it off does not seem to fix the problem.

4 Oct 2012, 6:44 PM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

I'm speaking of ANY and EVERY way in which YOUR site is different from official Zen Cart code.

And that's because I can't trigger any of the symptoms you describe when using clean unchanged v1.5.1 code.

As others stated earlier, that particular function was relocated to another file. So, either you didn't upload the new password_funcs.php, or your copy of that file (on your server) is missing that function. I know you said you did, and you said that you said so in your first post, but I don't even see where you said that either. But I'm not here to argue the point, and I don't mean to sound rude. The point is that your server can't find the function in the file, despite the fact that it should. And the only reason why it wouldn't find it is if it doesn't exist, or if you've got several other things changed that are preventing the files from loading the way they were designed to, such as altered files in /includes/auto_loaders or /includes/init_includes. So, basically you need to go back and make sure that you did indeed correctly upload all the new versions of the files to your server and that all of the uploads of all of those files were actually successful.

4 Oct 2012, 7:13 PM
#7
webmistressm avatar

webmistressm

New Zenner

Join Date:
Jan 2010
Location:
SoCal
Posts:
47
Plugin Contributions:
0

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

DrByte:

...and I don't mean to sound rude. The point is that your server can't find the function in the file, despite the fact that it should.

Yes. I just meant to insist that the file is present (I had checked all files that the phpxref site mentioned as my first way of figuring out why it might not be able to find that function. Before you got back to me with initial response, I had already looked inside as the files mentioned (both referenced and where it is defined). First thing I noticed was that of the 2 files that define it, functions_general.php being the one that did not. Looks like this is outdated documentation at any case since the 1.5.1 update.

DrByte:

...such as altered files in /includes/auto_loaders or /includes/init_includes.

Yeah. None of the files were changed when I ran a comparison, including the ones you mentioned. However, I did upload and activate a theme that was a slight modification (colors) off the classic theme. Could that be it?

4 Oct 2012, 7:55 PM
#8
webmistressm avatar

webmistressm

New Zenner

Join Date:
Jan 2010
Location:
SoCal
Posts:
47
Plugin Contributions:
0

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

Oh, I wish there was an edit button. That sounds even ruder than you were worried about coming across as. Text based communication on this issue did not execute properly. Apologies


**If after adding this rule (and a URI mapping to test) navigating to the new static URI results in a 404 or a 500 error, then it may be worth trying a slight variation of the rule, which some servers seem to require.

Try adding a slash to the front of index.php, this may resolve the problem: RewriteRule .* /index.php [QSA,L]**
Since the initial (and often vague) HTTP error is 500, this CeoN URI Mapping add-on documentation did catch my eye. However, it is related to my htaccess (which one, Ill have to find out) so it looks like I may want to take a look.

4 Oct 2012, 8:07 PM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

If you're not getting repeated entries of that "call to undefined function", then maybe it was a one-time thing that happened before the newer password_funcs file was uploaded. And thus all your other symptoms are related to something else.

As for URI Mapping, the .htaccess it's referring to is the one in the root of your site (or the root of your store). Not one that comes with Zen Cart (since the only .htaccess files that come with Zen Cart are all located in subdirectories, never in the root of your store).

4 Oct 2012, 8:28 PM
#10
webmistressm avatar

webmistressm

New Zenner

Join Date:
Jan 2010
Location:
SoCal
Posts:
47
Plugin Contributions:
0

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

DrByte:

If you're not getting repeated entries of that "call to undefined function", then maybe it was a one-time thing that happened before the newer password_funcs file was uploaded. And thus all your other symptoms are related to something else.

As for URI Mapping, the .htaccess it's referring to is the one in the root of your site (or the root of your store). Not one that comes with Zen Cart (since the only .htaccess files that come with Zen Cart are all located in subdirectories, never in the root of your store).

in my /public_html/, I had this one:

RewriteEngine On

# Don't rewrite any URIs ending with a file extension (ending with .[xxxxx])
RewriteCond %{REQUEST_URI} !\.[a-z]{2,5}$ [NC]
# Don't rewrite admin directory
RewriteCond %{REQUEST_URI} !^/admin [NC]
# Don't rewrite editors directory
RewriteCond %{REQUEST_URI} !^/editors [NC]
# Don't rewrite cPanel directories
RewriteCond %{REQUEST_URI} !/cpanel [NC]
RewriteCond %{REQUEST_URI} !/frontend [NC]
# Handle all other URIs using Zen Cart (index.php)
RewriteRule .* index.php?%{QUERY_STRING} [L]

and added the slash. No change in the 500 errors. Turning off the module completely but leaving that / modification in the .htaccess file didnt give me anything new. Well...perplexing and causing me to believe Im barking up the wrong tree on this url rewriting add-on. Honestly cant imagine what is preventing shopping_cart.php from seeing the function, despite its new place since 1.5.1. shakes head

4 Oct 2012, 8:32 PM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

I'm compelled to ask you this: You initially quoted a "Call to Undefined Function" error, presumably from debug logs.
What exactly must be done to trigger this error?
Can you consistently trigger it still? Or was it a one-time thing?

What have you gleaned about your 500 Internal Server Error messages from the server's apache logs? ref: http://www.zen-cart.com/content.php?105-why-am-i-getting-500-internal-server-error

4 Oct 2012, 8:47 PM
#12
webmistressm avatar

webmistressm

New Zenner

Join Date:
Jan 2010
Location:
SoCal
Posts:
47
Plugin Contributions:
0

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

DrByte:

I'm compelled to ask you this: You initially quoted a "Call to Undefined Function" error, presumably from debug logs.
What exactly must be done to trigger this error?
Can you consistently trigger it still? Or was it a one-time thing?

What have you gleaned about your 500 Internal Server Error messages from the server's apache logs? ref: http://www.zen-cart.com/content.php?105-why-am-i-getting-500-internal-server-error
Consistantly this error comes up. As I add different products to my cart in a browsing session, that blank page shows up every time. The error in debug is always the same. When I just refresh from that blank page, and thus directed to the shopping cartt contents, the same blank error (and same error in debug) occurs if I change the quantity in a shopping cart item's text field and press the "update quantity button" nearby.

As for access to the server's logs, is that possible to see when Im not hosting the content myself? Closest is a logs directory above my root public_html directory. It seems to only be access logs so maybe I will have to ask Hostica about this.

4 Oct 2012, 9:12 PM
#13
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

I'm trying to determine what sort of actual error you're encountering.

  1. If it's a PHP error, such as the "undefined function", then THAT is what you need to focus on fixing. And, as I said, the only reason it wouldn't be defined is if the file that defines it isn't present on the server or if the file isn't getting loaded because the files involved in doing the loading aren't getting loaded.

  2. If it's a "500" error, then you would need to research what's triggering the very generic 500 response, as explained in the article mentioned earlier.

Sounds like it's #1. So, you need to go back and do some debugging to determine whether that password_funcs file is actually being loaded or not, and of course that it contains the correct content ..... and that you're not mistakenly looking at it on the wrong server or wrong folder (I mention that just in case, since I made that mistake on something else earlier today LOL).

4 Oct 2012, 9:25 PM
#14
webmistressm avatar

webmistressm

New Zenner

Join Date:
Jan 2010
Location:
SoCal
Posts:
47
Plugin Contributions:
0

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

Honestly, I dont know how I would further debug in the case (with my current knowledge of Zencart) of #1 (the theory that something is blocking shopping cart from accessing the zen_create_random_value function.

Forgot to mention (as Im trying tot start simple before getting complicated): In chrome, I dont actually get a blank page. I figured that the specific http error was 500 because of the readout when I tried to reproduce the problem in Chrome (vs Firefox) :

Server error
The website encountered an error while retrieving http://www.prettygirlygirl.com/index.php?main_page=index&cPath=22_11&sort=20a&action=multiple_products_add_product&zenid=vq4io9ctrjmv64kfpf9ldh2fq6. It may be down for maintenance or configured incorrectly.
Here are some suggestions:
Reload this webpage later.
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request

4 Oct 2012, 9:30 PM
#15
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

Things I'd try:

  • Since password_funcs is involved with logging in, check to see if you can login
  • And since that random-value may be involved with resetting a password using the forgotten-password option, see if you can do that
  • Then see if the function that's allegedly "undefined" is used anywhere else in Zen Cart ... ie: search for its name using the Developers Toolkit from your admin, or using a good text-file-search tool on your PC if you have one (an indispensible tool)
  • Then try editing the first line of that password-funcs file and insert <?php die('found password_funcs.php');?> on the first line to see if that message displays when the file loads. If so, then you know you're looking at the right file and that it's actually being called, etc.
  • if the die() message doesn't display, then go look for the places where password_funcs.php file is actually loaded from, and make sure those files aren't damaged. Do all this on a clean uncustomized set of ZC files.
  • etc
4 Oct 2012, 9:45 PM
#16
webmistressm avatar

webmistressm

New Zenner

Join Date:
Jan 2010
Location:
SoCal
Posts:
47
Plugin Contributions:
0

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

Alright. :)

DrByte:

Things I'd try:

  • Since password_funcs is involved with logging in, check to see if you can login
  • And since that random-value may be involved with resetting a password using the forgotten-password option, see if you can do that

Are you talking about a shopper login (vs your admin one)?

DrByte:

  • Then see if the function that's allegedly "undefined" is used anywhere else in Zen Cart ... ie: search for its name using the Developers Toolkit from your admin, or using a good text-file-search tool on your PC if you have one (an indispensible tool)

**/hsphere/local/home/user/prettygirlygirl.com/includes/functions/password_funcs.php

Line #49 : function zen_create_random_value($length, $type = 'mixed') **

DrByte:

  • Then try editing the first line of that password-funcs file and insert <?php die('found password_funcs.php');?> on the first line to see if that message displays when the file loads. If so, then you know you're looking at the right file and that it's actually being called, etc.
    I altered the file with the message but how do I test to see if it displays? Do you mean "reproduce the problem" and see if that blank page displays the message instead?
4 Oct 2012, 9:54 PM
#17
webmistressm avatar

webmistressm

New Zenner

Join Date:
Jan 2010
Location:
SoCal
Posts:
47
Plugin Contributions:
0

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

Incidentally, when I load the main domaain of my site, I did indeed get the found password_funcs.php to show up on the page now. :)

4 Oct 2012, 10:00 PM
#18
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

WebmistressM:

Incidentally, when I load the main domaain of my site, I did indeed get the found password_funcs.php to show up on the page now. :)
Good. So that means the file is getting loaded.

It also means that if "undefined function" is triggered, then that file doesn't contain that function.

So, while this may sound awfully basic, let's look at that file, on the server. Copy and paste its contents here.

(I'd normally just upload the good clean correct copy, replacing the one on the server. But I'm curious to know what's actually in the file since it's apparently bad.)

Then, to put the site back online again, just upload the good clean v1.5.1 version of that file. And test that the storefront displays properly again, and that you can login. And then test the shopping cart stuff that you said could consistently trigger the problem.

4 Oct 2012, 10:08 PM
#19
webmistressm avatar

webmistressm

New Zenner

Join Date:
Jan 2010
Location:
SoCal
Posts:
47
Plugin Contributions:
0

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

Here is the copy/paste of function

<?php
/**
 * password_funcs functions
 *
 * @package functions
 * @copyright Copyright 2003-2012 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version GIT: $Id: Author: Ian Wilson  Wed Aug 29 13:38:15 2012 +0100 Modified in v1.5.1 $
 */

////
// This function validates a plain text password with an encrpyted password
function zen_validate_password($plain, $encrypted)
{
  if (zen_not_null($plain) && zen_not_null($encrypted))
  {
    // split apart the hash / salt
    $stack = explode(':', $encrypted);

    if (sizeof($stack) != 2)
      return false;

    if (md5($stack[1] . $plain) == $stack[0])
    {
      return true;
    }
  }

  return false;
}
////
// This function makes a new password from a plaintext password.
function zen_encrypt_password($plain)
{
  $password = '';

  for ($i = 0; $i < 10; $i++)
  {
    $password .= zen_rand();
  }

  $salt = substr(md5($password), 0, 2);

  $password = md5($salt . $plain) . ':' . $salt;

  return $password;
}
////
function zen_create_random_value($length, $type = 'mixed')
{
  if (($type != 'mixed') && ($type != 'chars') && ($type != 'digits'))
    return false;

  $rand_value = '';
  while (strlen($rand_value) < $length)
  {
    if ($type == 'digits')
    {
      $char = zen_rand(0, 9);
    } else
    {
      $char = chr(zen_rand(0, 255));
    }
    if ($type == 'mixed')
    {
      if (preg_match('/^[a-z0-9]$/i', $char))
        $rand_value .= $char;
    } elseif ($type == 'chars')
    {
      if (preg_match('/^[a-z]$/i', $char))
        $rand_value .= $char;
    } elseif ($type == 'digits')
    {
      if (preg_match('/^[0-9]$/', $char))
        $rand_value .= $char;
    }
  }
  
  if ($type == 'mixed' && !preg_match('/^(?=.*[\w]+.*)(?=.*[\d]+.*)[\d\w]{' . $length . ',}$/', $rand_value))
  {
    $rand_value .= zen_rand(0, 9);
  }

  return $rand_value;
}
function zen_get_entropy($seed)
{
  $entropy = '';
  $fp = @fopen('/dev/urandom', 'rb');
  if ($fp !== FALSE)
  {
    $entropy .= @fread($fp, 16);
    //    echo "USING /dev/random" . "<br>";
    @fclose($fp);
  }
  // MS-Windows platform?
  if (@class_exists('COM'))
  {
    // http://msdn.microsoft.com/en-us/library/aa388176(VS.85).aspx
    try
    {
      $CAPI_Util = new COM('CAPICOM.Utilities.1');
      $entropy .= $CAPI_Util->GetRandom(16, 0);

      if ($entropy)
      {
        $entropy = md5($entropy, TRUE);
        //echo "USING WINDOWS" . "<br>";
      }
    } catch (Exception $ex)
    {
      // echo 'Exception: ' . $ex->getMessage();
    }
  }
  if (strlen($entropy) < 16)
  {
    $entropy = sha1_file('/includes/configure.php');
    $entropy .= microtime() . mt_rand() . $seed;
    //echo "USING FALLBACK" . "<br>";
  }
  return sha1($entropy);
}
function zen_create_PADSS_password($length = 8)
{
  $charsAlpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  $charsNum = '0123456789';
  $charsMixed = $charsAlpha . $charsNum;
  $password = "";
  for ($i = 0; $i < $length; $i++)
  {
    $addChar = substr($charsMixed, zen_pwd_rand(0, strlen($charsMixed) - 1), 1);
    while (strpos($password, $addChar))
    {
      $addChar = substr($charsMixed, zen_pwd_rand(0, strlen($charsMixed) - 1), 1);
    }
    $password .= $addChar;
  }
  if (!preg_match('/[0-9]/', $password))
  {
    $addChar = substr($charsNum, zen_pwd_rand(0, strlen($charsNum) - 1), 1);
    $addPos = zen_pwd_rand(0, strlen($password) - 1);
    $password[$addPos] = $addChar;
  }
  return $password;
}
function zen_pwd_rand($min = 0, $max = 10)
{
  static $seed;
  if (!isset($seed))
    $seed = zen_get_entropy(microtime());
  $random = zen_get_entropy($seed);
  $random .= zen_get_entropy($random);
  $random = sha1($random);
  $random = substr($random, 0, 8);
  $value = abs(hexdec($random));
  $value = $min + (($max - $min + 1) * ($value / (4294967295 + 1)));
  $value = abs(intval($value));
  return $value;
}

DrByte:

Then, to put the site back online again, just upload the good clean v1.5.1 version of that file. And test that the storefront displays properly again, and that you can login. And then test the shopping cart stuff that you said could consistently trigger the problem.

Login...do you mean from the backend (admining the store) or a customer's login (from site.com/index.php?main_page=login ) ?

4 Oct 2012, 10:16 PM
#20
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Blank Page on "Add to Cart" - Call to Undefined Function zen_create_random_value

"storefront" = "customer's login", ie: a place where a customer could access and trigger the shopping-cart problem you've been talking about.

The admin doesn't trigger the shopping-cart problem, right?