开发者

Fatal error: Call to undefined function: strripos()

开发者 https://www.devze.com 2023-04-13 06:01 出处:网络
I get this error only in safari and the android browser. All my code does is redirect the page based on the browser? works fine everywhere else, any suggestions

I get this error only in safari and the android browser. All my code does is redirect the page based on the browser? works fine everywhere else, any suggestions ?

"Fatal error: Call to undefined function: strripos() in /home/content/a/l/i/aliahealthcare/html/Register-With-Alia.php on line 65"

<?php
 function getBrowser() 
{ 
$u_agent = $_SERVER['HTTP_USER_AGENT']; 
$bname = 'Unknown';
$platform = 'Unknown';
$version= "";

//First get the platform?
if (preg_match('/linux/i', $u_agent)) {
    $platform = 'linux';
}
elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
    $platform = 'mac';
}
elseif (preg_match('/windows|win32/i', $u_agent)) {
    $platform = 'windows';
}

// Next get the name of the useragent yes seperately and for good reason
if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent)) 
{ 
    $bname = 'Internet Explorer'; 
    $ub = "MSIE"; 
} 
elseif(preg_match('/Firefox/i',$u_agent)) 
{ 
    $bname = 'Mozilla Firefox'; 
    $ub = "Firefox"; 
} 
elseif(preg_match('/Chrome/i',$u_agent)) 
{ 
    $bname = 'Google Chrome'; 
    $ub = "Chrome"; 
} 
elseif(preg_match('/Safari/i',$u_agent)) 
{ 
    $bname = 'Apple Safari'; 
    $ub = "Safari"; 
} 
elseif(preg_match('/Opera/i',$u_agent)) 
{ 
    $bname = 'Opera'; 
    $ub = "Opera"; 
} 
elseif(preg_match('/Netscape/i',$u_agent)) 
{ 
    $bname = 'Netscape'; 
    $ub = "Netscape"; 
} 

// finally get the correct version number
$known = array('Version', $ub, 'other');
$pattern = '#(?<browser>' . join('|', $known) .
')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
if (!preg_match_all($pattern, $u_agent, $matches)) {
    // we have no matching number just continue
}

// see how many we have
$i = count($matches['browser']);
if ($i != 1) {
    //we will have two since we are not using 'other' argument yet
    /开发者_高级运维/see if version is before or after the name
    if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
        $version= $matches['version'][0];
    }
    else {
        $version= $matches['version'][1];
    }
}
else {
    $version= $matches['version'][0];
}

// check if we have a number
if ($version==null || $version=="") {$version="?";}

return array(
    'userAgent' => $u_agent,
    'name'      => $bname,
    'version'   => $version,
    'platform'  => $platform,
    'pattern'    => $pattern
);
} 

// now try it
$ua=getBrowser();

if ($ua['name'] == 'Internet Explorer')
{ header( 'Location: http://www.aliahealthcare.com/Register-IE.php' ) ; }
else {  header( 'Location: http://aliahealthcare.com/New-User.php' ) ;}

?>


Check to see what version of PHP you are running by calling phpinfo() in a document.

 strripos - PHP5
 strrpos - PHP4/5

If you are running php4 change it to strrpos(....), it is the still the same format.

Depending on your hosting server you can force php5 by adding the following lines to your htaccess

 AddType x-mapp-php5 .php
 AddHandler x-mapp-php5 .php


You are probably using PHP4, which doesn't support strripos().

You can check your version with echo PHP_VERSION.


In addition to the PHP 4 answers, another thing is your regular expression user agent check.

PHP has included the get_browser() function which has been available since PHP 4.

All you really need to do is :

$browser = get_browser(null, true);

if (strtolower($browser['browser']) == 'firefox'){
   header() //redirect to wherever
}

Or just use a switch statement.

Note :

In order for this to work, your browscap configuration setting in php.ini must point to the correct location of the browscap.ini file on your system.

browscap.ini is not bundled with PHP, but you may find an up-to-date » php_browscap.ini file here.

While browscap.ini contains information on many browsers, it relies on user updates to keep the database current. The format of the file is fairly self-explanatory.

http://browsers.garykeith.com/downloads.asp


According to the error, PHP is not aware about strripos().

I suppose you are using PHP4, since this function was introduced in PHP5.


This could happen if you are using a version of PHP before 5; strripos was added in PHP5.

0

精彩评论

暂无评论...
验证码 换一张
取 消