HJÄLP!!! Klarna API | HTTP_X_FORWARDED_FOR

Visa första olästa
Ämnesverktyg
Visa huvudforum
Visningsalternativ
Oläst 2013-03-07, 13:05 #1
seoonlineseoonline är inte uppkopplad
Nykomling
Reg.datum: Sep 2012
Inlägg: 12
Standard HJÄLP!!! Klarna API | HTTP_X_FORWARDED_FOR

I have a problem when checkingout in my webshop. Website sends a "internal" ip ( 10.0.18.5) from isp and my payment gateway dont accept it.

My isp tells me to change this:
$_SERVER['REMOTE_ADDRESS'] ===> $_SERVER['HTTP_X_REAL_IP']
(not working)

My payment gateway tell me to change:
return $tmp_ip; ====> return $_SERVER["HTTP_X_FORWARDED_FOR"];

My Code:

PHP
/**
     * Returns the clients IP address.
     *
     * @return string
     */
    public function getClientIP() {
        //Proxy handling.
        $tmp_ip = $_SERVER['REMOTE_ADDR'];
        $x_fwd = isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : null;
        if(self::$x_forwarded_for && $x_fwd !== null) {
            //Cut out the first IP address
            if(($cpos = strpos($x_fwd, ',')) !== false) {
                $tmp_ip = substr($x_fwd, 0, $cpos);
                $x_fwd = substr($x_fwd, $cpos+2);
            }
            else { //Only one IP address
                $tmp_ip = $x_fwd;
                $x_fwd = null;
            }
        }
        $this->x_fwd = $x_fwd;

        return $tmp_ip;          
    }



HELP!!!!!!!!!!
seoonline är inte uppkopplad
Oläst 2013-03-07, 14:53 #2
hnnhnn är inte uppkopplad
Banned
hnns avatar
Reg.datum: Mar 2004
Inlägg: 2 587
Vad säger:
CODE
print_r($_SERVER);
hnn är inte uppkopplad
Oläst 2013-03-07, 15:06 #3
seoonlineseoonline är inte uppkopplad
Nykomling
Reg.datum: Sep 2012
Inlägg: 12
Var skall jag skriva/byta ut det?
seoonline är inte uppkopplad
Oläst 2013-03-07, 15:07 #4
seoonlineseoonline är inte uppkopplad
Nykomling
Reg.datum: Sep 2012
Inlägg: 12
PHP
   /**
     * Returns the clients IP address.
     *
     * @return string
     */
    public function getClientIP() {
        //Proxy handling.
        $tmp_ip = $_SERVER['REMOTE_ADDR'];
        $x_fwd = isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : null;
        if(self::$x_forwarded_for && $x_fwd !== null) {
            //Cut out the first IP address
            if(($cpos = strpos($x_fwd, ',')) !== false) {
                $tmp_ip = substr($x_fwd, 0, $cpos);
                $x_fwd = substr($x_fwd, $cpos+2);
            }
            else { //Only one IP address
                $tmp_ip = $x_fwd;
                $x_fwd = null;
            }
        }
        $this->x_fwd = $x_fwd;

        return $tmp_ip;
    }
seoonline är inte uppkopplad
Oläst 2013-03-07, 15:35 #5
seoonlineseoonline är inte uppkopplad
Nykomling
Reg.datum: Sep 2012
Inlägg: 12
Resolved!

PHP
    /**
     * Returns the clients IP address.
     *
     * @return string
     */
    public function getClientIP() {
        //Proxy handling.
        $tmp_ip = $_SERVER['REMOTE_ADDR'];
        $x_fwd = isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : null;
        if(self::$x_forwarded_for && $x_fwd !== null) {
            //Cut out the first IP address
            if(($cpos = strpos($x_fwd, ',')) !== false) {
                $tmp_ip = substr($x_fwd, 0, $cpos);
                $x_fwd = substr($x_fwd, $cpos+2);
            }
            else { //Only one IP address
                $tmp_ip = $x_fwd;
                $x_fwd = null;
            }
        }
        $this->x_fwd = $x_fwd;

        return $_SERVER['HTTP_X_REAL_IP'];
    }
seoonline är inte uppkopplad
Oläst 2013-03-08, 09:43 #6
allstarsallstars är inte uppkopplad
Klarade millennium-buggen
Reg.datum: Apr 2006
Inlägg: 2 126
Därmed bara så här:
PHP
public function getClientIP() { 
        return $_SERVER['HTTP_X_REAL_IP']; 
    }  
allstars är inte uppkopplad
Oläst 2013-03-08, 11:07 #7
ClarenceClarence är inte uppkopplad
Administratör
Reg.datum: Jan 2003
Inlägg: 1 974
Citat:
Ursprungligen postat av allstars Visa inlägg
Därmed bara så här:
PHP
public function getClientIP() { 
        return $_SERVER['HTTP_X_REAL_IP']; 
    }  

Förutsatt att self::$x_fwd inte alls används i någon annan funktion, lite farlig och osannolik gissning.
Clarence är inte uppkopplad
Taggar
api, error, woocommerce, wordpress
Aktiva användare som för närvarande tittar på det här ämnet: 0 (0 medlemmar och 0 gäster)