please help with EREG() arguments

Started on the old forum in May 2011 · view the original in the archive · old links redirect here

#error #function #php #social-network

12 replies · 1,509 views · started 15 years ago · 1 min read

7 participants
s3nzo Developer · 156 posts #1

Hey guys i activated the jcow mobile view and now on a desktop site i get an error

Warning: eregi() [function.eregi]: REG_EMPTY in /home/*****/.../on mobile.hook.php in line 18

And here is the source mobile.hook.php

<?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');
                }
            }
        }
    }
}
firemax Developer · 221 posts #2

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.

External image (may be gone) Free Mobile Web Scripts by me: Free Youtube Downloader, Tweets Reader, Facebook Wall Posts Reader PHP Tutorials: [How to Secure Your PHP Script (PHP SECURITY)](http://coding-talk.com/f14/how-to-secure-you…

subzero Super moderator Fellow · 3,954 posts #3

ereg to preg

Easy lol

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

kei_ki7 Senior · 431 posts #4

Don't use ereg, use preg

Did I help you? You can help me too Your donations will help me finance my studies.

Ponick Developer · 216 posts #5

add "@" before eregi mean @eregi it may work ! And remember eregi() is not case sensitive

/* I don't know everything hehe */

Find me on facebook

arnage Lead · 811 posts #6

Try:

/* ############################################################ *\
 ----------------------------------------------------------------
@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');
                }
            }
        }
    }
}

It should work but if no:

/* ############################################################ *\
 ----------------------------------------------------------------
@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');
                }
            }
        }
    }
}

Its just from head and if doesn't work tell, gonna test it. 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
s3nzo Developer · 156 posts #7

Ponick wrote: add "@" before eregi mean @eregi it may work ! And remember eregi() is not case sensitive

Thanks ponick it worked and thanks to everyone else for helping

arnage Lead · 811 posts #8

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. 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
Ponick Developer · 216 posts #9

arnage wrote: 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. :)

dude, i know its not so good to ignore error using "@" but when things come to hurry people want the most short-cut way lolz

/* I don't know everything hehe */

Find me on facebook

CreativityKills Lead · 833 posts #10

Ponick wrote: dude, i know its not so good to ignore error using "@" but when things come to hurry people want the most short-cut way lolz

using @ to suppress errors suck. Find a better way to fix it without @.

Added after 5 minutes:

s3nzo wrote: Hey guys i activated the jcow mobile view and now on a desktop site i get an error

Warning: eregi() [function.eregi]: REG_EMPTY in /home/*****/.../on mobile.hook.php in line 18

try this mobile.hook.php

<?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');
                }
            }
        }
    }
}
arnage Lead · 811 posts #11

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:

Array(
	$id[0] = null;
	$id[1] = null;
	$id[2] = null;
	$id[3] = null;
// and so on...
)

... because it gets only the var, not its value, which ofcourse issued a:

Warning: eregi() [function.eregi]: REG_EMPTY in /home/*****/.../on mobile.hook.php in line 18

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). So, the correct way allong with upgrade to preg_match (where matching pattern must be in double quotes) looks like:

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');
                }
            }
        }
    }
}  

Simple as that. 🙂

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.

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');
                }
            }
    }
}  

🤝

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
s3nzo Developer · 156 posts #12

arnage wrote: the correct way allong with upgrade to preg_match (where matching pattern must be in double quotes) looks like:

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');
                }
            }
        }
    }
}  

I'm using fedora and this code redirects me to a mobile version

arnage Lead · 811 posts #13

Fedora is operating system, not browser so it doesn't matter.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close