2014-07-24 3 views
0

file_get_contents를 사용하여 서버의 IP 주소와 다른 IP 주소를 사용하는 PHP 스크립트가있는 방법이 있습니까? 우리는 5 개의 IP 주소를 가지고 있으며이 목적을 위해 특정 IP 주소를 활용하려고합니다.특정 IP 주소로 PHP 스크립트를 실행하는 방법이 있습니까

+0

@skrilled OP는'file_get_contents' 요청의 원본 IP를 변경하려고합니다. –

+1

원하는 IP가있는 시스템에서 호출을 실행하십시오 ... –

+0

아, 이제 알겠습니다. 너무 빨리 읽는 것이 좋지 않습니다. 이것은 여전히 ​​문서에서 대답하고있는 무언가입니다. – skrilled

답변

1

예, 가능합니다. 사용하려는 스트림 컨텍스트를 구성해야합니다.

<?php 
// context options 
$ctxopts = array(
    'socket' => array(
     'bindto' => '192.168.0.100:0', 
    ), 
); 

// create the context... 
$context = stream_context_create($ctxopts); 

// ...and use it to fetch the data 
echo file_get_contents('http://www.example.com', false, $context); 

당신은 php.net

context 
A valid context resource created with stream_context_create(). If you don't need to use a custom context, you can skip this parameter by NULL. 

stream_context_create()'s documentation에 쉽게 접근 할 수있는 documentationhttp://php.net/manual/en/context.socket.php

0

에 대한 자세한 정보를 얻을 수 있습니다 나머지

$opts = array(
    'socket' => array(
     'bindto' => '123.123.123.123:0', // 0 for automatically determine port 
    ) 
); 

최종 코드를 설명합니다 :

$opts = array(
    'socket' => array(
     'bindto' => '123.123.123.123:0', // 0 for automatically determine port 
    ) 
);  
$stream = stream_context_create($ctxopts); 
echo file_get_contents('http://www.website', false, $stream); 
관련 문제