WN

WN (https://www.wn.se/forum/index.php)
-   Serversidans teknologier (https://www.wn.se/forum/forumdisplay.php?f=4)
-   -   HJÄLP!!! Klarna API | HTTP_X_FORWARDED_FOR (https://www.wn.se/forum/showthread.php?t=1057130)

seoonline 2013-03-07 12:05

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-kod:

/**
     * 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_fwd0$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!!!!!!!!!!

hnn 2013-03-07 13:53

Vad säger:
Kod:

print_r($_SERVER);

seoonline 2013-03-07 14:06

Var skall jag skriva/byta ut det?

seoonline 2013-03-07 14:07

PHP-kod:

   /**
     * 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_fwd0$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 2013-03-07 14:35

Resolved!

PHP-kod:

    /**
     * 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_fwd0$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'];
    } 


allstars 2013-03-08 08:43

Därmed bara så här:
PHP-kod:

public function getClientIP() { 
        return 
$_SERVER['HTTP_X_REAL_IP']; 
    } 


Clarence 2013-03-08 10:07

Citat:

Ursprungligen postat av allstars (Inlägg 20464343)
Därmed bara så här:
PHP-kod:

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.


Alla tider är GMT +2. Klockan är nu 17:51.

Programvara från: vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Svensk översättning av: Anders Pettersson