ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

encoding of the dots in the {ip_address}

June 23, 2007 5:14am

Subscribe [2]
  • #1 / Jun 23, 2007 5:14am

    ussher

    14 posts

    Hi
    Im having a problem that appears to be the . in the ipaddress when retrieved using {ip_address} global variable.

    I have 2 variables that look identical to the eye:
    (125.3.114.233) and
    (125.3.114.233)

    the first comes from the database and the second is from the {ip_address} global variable.

    If i try to remove the dots using php i get
    (1253114233) and
    (125.3.114.233)

    Which leads me to believe that the dots are somehow different.  I would like to know how they are different.

    {exp:query sql="SELECT field_id_40 AS customers, t.entry_id, t.ip_address as ip FROM ee_weblog_titles AS t, ee_weblog_data AS d WHERE t.entry_id = d.entry_id AND t.weblog_id = d.weblog_id AND t.status ='Pending' AND t.weblog_id='8' AND t.title LIKE 'O;OKING:%' order by t.entry_id DESC limit 0,1"}
    e:{entry_id}
    
    c:{customers}
    
    i:{ip}
    <?php
    $ipAddress = "{ip}";
    $currentIP = "{ip_address}";
    
    print "ipaddress:$ipAddress
    ";
    print "currentipaddress:$currentIP
    ";
    
    $a = trim($ipAddress);
    $A = str_replace(".", "", $a);
    $b = trim($currentIP);
    $B = str_replace(".", "", $b);
    
    if($A==$B){
     echo "The IP's match";
     }else{
     echo "No Ip match: ($A): ($B)";
     }
    ?>
    {/exp:query}

    im getting output like this
    ipaddress:125.3.114.233
    currentipaddress:125.3.114.233
    No Ip match: (125.3.114.233): (125.3.114.233)

    when i add the str_replace to remove the dots . and try to just compare the numbers i am unable to remove them from the ipaddress generated using the {ip_address} global variable.

    They look like normal dots but i cant get the ip from the database to match the current ip.

    Know of any reason this might be happening?

    I have tried copying the output dots and substituting them in the str_replace function but that did not fix things.

    Thanks

  • #2 / Jun 23, 2007 8:23am

    Derek Jones

    7561 posts

    The global variable is not parsed until the very end of template parsing, so your PHP is actually seeing {ip_address}, literally.  You can demonstrate this by making sure you exit the script after printing the variables:

    $ipAddress = "{ip}";
    $currentIP = "{ip_address}";
    
    print "ipaddress:$ipAddress
    ";
    print "currentipaddress:$currentIP
    ";
    exit;

    Incidentally, to get the current IP address you can just use the Input class:

    global $IN;
    echo $IN->IP;
  • #3 / Jun 24, 2007 5:29am

    ussher

    14 posts

    Champion!

    It never occured to me that it was still the placeholder that i was comparing.  I Thought it was an encoding problem.

    Thank you very much. Problem Fixed.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases