please help with EREG() arguments
Collapse
X
-
I'm using fedora and this code redirects me to a mobile versionOriginally posted by arnage View Postthe correct way allong with upgrade to preg_match (where matching pattern must be in double quotes) looks like:
PHP Code:function mobile_boot() { global $parr; if ($parr[0] == 'home' || !$parr[0]) { if (!$mobile_ids = get_text('mobile_ids')) { $mobile_ids = 'iphone,nokia,BlackBerry,HTC,Motorola,Nokia,Samsung'; } $ids = explode(',',$mobile_ids); if (is_array($ids)) { foreach($ids as $key => $id) { if (preg_match("/$id/i", $_SERVER['HTTP_USER_AGENT'])) { //This is line 18 redirect('mobile'); } } } } }
Leave a comment:
-
I'd prefer to fix the error rather than to kill an entire function.
The @ sign is to prevent error, not fix it, and this is the same as that he deleted the entire function, as it does not exist it does not redirecting anything.
Lets see step by step.
Problem is in loop actualy, when creating an array with explode() and do loop like foreach($ids as $id), the array looks like this:
... because it gets only the var, not its value, which ofcourse issued a:Code:Array( $id[0] = null; $id[1] = null; $id[2] = null; $id[3] = null; // and so on... )
A quick fix wuld bee adding the key var in loop to read the value of that var, just to add foreach($ids as $key => $id).Code:Warning: eregi() [function.eregi]: REG_EMPTY in /home/*****/.../on mobile.hook.php in line 18
So, the correct way allong with upgrade to preg_match (where matching pattern must be in double quotes) looks like:
Simple as that.PHP Code:function mobile_boot() { global $parr; if ($parr[0] == 'home' || !$parr[0]) { if (!$mobile_ids = get_text('mobile_ids')) { $mobile_ids = 'iphone,nokia,BlackBerry,HTC,Motorola,Nokia,Samsung'; } $ids = explode(',',$mobile_ids); if (is_array($ids)) { foreach($ids as $key => $id) { if (preg_match("/$id/i", $_SERVER['HTTP_USER_AGENT'])) { //This is line 18 redirect('mobile'); } } } } }
Another a little more elegant way would be to take out explode() and create the array right there and simple loop thru it.
Note that user agent is actualy a user input so that im adding urlencode() to the $_SERVER var.
PHP Code:function mobile_boot() { global $parr; if ($parr[0] == 'home' || !$parr[0]) { if (!$mobile_ids = get_text('mobile_ids')) { $mobile_ids = array('iphone', 'nokia', 'BlackBerry', 'HTC', 'Motorola', 'Nokia', 'Samsung'); } // it is an array foreach($mobile_ids as $id) { if (preg_match("/$id/i", urlencode($_SERVER['HTTP_USER_AGENT']))) { //This is line 18 redirect('mobile'); } } } }
Last edited by arnage; 17.05.11, 19:49.
Leave a comment:
-
using @ to suppress errors suck. Find a better way to fix it without @.Originally posted by Ponick View Postdude, i know its not so good to ignore error using "@" but when things come to hurry people want the most short-cut way lolz
Added after 5 minutes:
try this mobile.hook.phpOriginally posted by s3nzo View PostHey guys i activated the jcow mobile view and now on a desktop site i get an error
Code:Warning: eregi() [function.eregi]: REG_EMPTY in /home/*****/.../on mobile.hook.php in line 18
PHP Code:<?php /* ############################################################ *\ ---------------------------------------------------------------- @package Jcow Social Networking Script. @copyright Copyright (C) 2009 - 2010 jcow.net. All Rights Reserved. @license see http://jcow.net/license ---------------------------------------------------------------- \* ############################################################ */ function mobile_boot() { global $parr; if ($parr[0] == 'home' || !$parr[0]) { if (!$mobile_ids = get_text('mobile_ids')) { $mobile_ids = 'iphone,nokia,BlackBerry,HTC,Motorola,opera mini,Samsung'; } $ids = explode(',',strtolower($mobile_ids)); if (is_array($ids)) { foreach ($ids as $id) { if (stristr(strtolower($_SERVER['HTTP_USER_AGENT']), trim($id))) { //This is line 18 redirect('mobile'); } } } } }Last edited by CreativityKills; 17.05.11, 12:37.
Leave a comment:
-
dude, i know its not so good to ignore error using "@" but when things come to hurry people want the most short-cut way lolzOriginally posted by arnage View PostIt doesn't work, u just killed the error with @. I mean, script now works but this function don't and same result u could achieve if just delete whole function and it call. Plus, i think the problem is in loop and not ereg because its still in the sistem even if its depreced, for now. Anyway, as u wish.
Leave a comment:
-
It doesn't work, u just killed the error with @. I mean, script now works but this function don't and same result u could achieve if just delete whole function and it call. Plus, i think the problem is in loop and not ereg because its still in the sistem even if its depreced, for now. Anyway, as u wish.
Last edited by arnage; 17.05.11, 10:38.
Leave a comment:
-
Try:
It should work but if no:PHP Code:/* ############################################################ *\ ---------------------------------------------------------------- @package Jcow Social Networking Script. @copyright Copyright (C) 2009 - 2010 jcow.net. All Rights Reserved. @license see http://jcow.net/license ---------------------------------------------------------------- \* ############################################################ */ function mobile_boot() { global $parr; if ($parr[0] == 'home' || !$parr[0]) { if (!$mobile_ids = get_text('mobile_ids')) { $mobile_ids = 'iphone,nokia,BlackBerry,HTC,Motorola,Nokia,Samsung'; } $ids = explode(',',$mobile_ids); if (is_array($ids)) { foreach ($ids as $id) { if (preg_match("/$id/i",$_SERVER['HTTP_USER_AGENT'])) { //This is line 18 redirect('mobile'); } } } } }
Its just from head and if doesn't work tell, gonna test it.PHP Code:/* ############################################################ *\ ---------------------------------------------------------------- @package Jcow Social Networking Script. @copyright Copyright (C) 2009 - 2010 jcow.net. All Rights Reserved. @license see http://jcow.net/license ---------------------------------------------------------------- \* ############################################################ */ function mobile_boot() { global $parr; if ($parr[0] == 'home' || !$parr[0]) { if (!$mobile_ids = get_text('mobile_ids')) { $mobile_ids = 'iphone,nokia,BlackBerry,HTC,Motorola,Nokia,Samsung'; } $ids = explode(',',$mobile_ids); if (is_array($ids)) { foreach ($ids as $id) { if(stristr($_SERVER['HTTP_USER_AGENT'], $id) === true) { //This is line 18 redirect('mobile'); } } } } }
Last edited by arnage; 16.05.11, 21:24.
Leave a comment:
-
add "@" before eregi mean @eregi it may work ! And remember eregi() is not case sensitive
Leave a comment:
-
This function has been deprecated and no longer available to use in any php applications. anyway, seems like the application is passing an empty variable to the eregi function. contact the script developer.
Leave a comment:
-
please help with EREG() arguments
Hey guys i activated the jcow mobile view and now on a desktop site i get an error
And here is the source mobile.hook.phpCode:Warning: eregi() [function.eregi]: REG_EMPTY in /home/*****/.../on mobile.hook.php in line 18
PHP Code:<?php /* ############################################################ *\ ---------------------------------------------------------------- @package Jcow Social Networking Script. @copyright Copyright (C) 2009 - 2010 jcow.net. All Rights Reserved. @license see http://jcow.net/license ---------------------------------------------------------------- \* ############################################################ */ function mobile_boot() { global $parr; if ($parr[0] == 'home' || !$parr[0]) { if (!$mobile_ids = get_text('mobile_ids')) { $mobile_ids = 'iphone,nokia,BlackBerry,HTC,Motorola,Nokia,Samsung'; } $ids = explode(',',$mobile_ids); if (is_array($ids)) { foreach ($ids as $id) { if (eregi(trim($id),$_SERVER['HTTP_USER_AGENT'])) { //This is line 18 redirect('mobile'); } } } } }
Leave a comment: