please help with EREG() arguments

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • arnage
    replied
    Fedora is operating system, not browser so it doesn't matter.
    Last edited by arnage; 19.05.11, 17:51. Reason: changed my mind.

    Leave a comment:


  • s3nzo
    replied
    Originally posted by arnage View Post
    the 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');
                    }
                }
            }
        }
    } 
    
    I'm using fedora and this code redirects me to a mobile version

    Leave a comment:


  • arnage
    replied
    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:
    Code:
    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:
    Code:
    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:
    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');
                    }
                }
            }
        }
    } 
    
    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.
    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:


  • CreativityKills
    replied
    Originally posted by Ponick View Post
    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:

    Originally posted by s3nzo View Post
    Hey 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
    try this mobile.hook.php

    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:


  • Ponick
    replied
    Originally posted by arnage View Post
    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

    Leave a comment:


  • arnage
    replied
    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:


  • s3nzo
    replied
    Originally posted by Ponick View Post
    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

    Leave a comment:


  • arnage
    replied
    Try:
    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');
                    }
                }
            }
        }
    } 
    
    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(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.
    Last edited by arnage; 16.05.11, 21:24.

    Leave a comment:


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

    Leave a comment:


  • kei_ki7
    replied
    Don't use ereg, use preg

    Leave a comment:


  • subzero
    replied
    ereg to preg

    Easy lol

    Leave a comment:


  • firemax
    replied
    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:


  • s3nzo
    started a topic please help with EREG() arguments

    please help with EREG() arguments

    Hey 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
    And here is the source mobile.hook.php

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