Oscoomerce tep_create_random_value($ length,'digits');函数不起作用

问题描述 投票:0回答:1

此功能generate_cart_id()不起作用。将PHP版本5.6更新到7.2后进行Oscommerce。

文件:catalog / includes / classes / shopping_cart.php

function generate_cart_id($length = 5) {
  return tep_create_random_value($length, 'digits');
}
php updates oscommerce
1个回答
0
投票

尝试此功能,我们将其用于php 5.4-7.4上的oscoommerce templates

function tep_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=tep_rand(0, 9);
    }else {
        $char=chr(tep_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;

}

© www.soinside.com 2019 - 2024. All rights reserved.