电影中心 精品软件 联系我们

 找回密码
 立即注册

QQ登录

只需一步,快速开始

Close
查看: 403|回复: 0

使用php配置代理访问百度简单示例

[复制链接]
发表于 2020-3-4 16:37:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
// 要访问的目标页面
* s- C3 b1 M& \- ^7 K2 r3 \        $url = "http://baidu.org/ip";0 M: W' n. e2 Q" F' P* A7 o3 E+ V1 j
        $urls = "https://baidu.org/ip";" i: N3 Z6 C6 T9 P# x- F

  r1 t% ^6 _, T2 I        // 代理服务器
. _7 |6 Z9 n6 v- G# l+ I        define("PROXY_SERVER", "tcp://t.xxxx.cn:31111");
) y  ~9 f" G" L! H) |7 H
4 q, w/ f* K5 t8 `* J: j+ c        // 隧道身份信息
6 |* Y, a' Y% b; O        define("PROXY_USER", "xxxxx");
( g0 n% D6 e7 o+ R3 r  e7 U2 R        define("PROXY_PASS", "123456");! p6 H" G) G8 ^" `- w% W+ {

3 |2 }- }# Z% e2 x& f6 |        $proxyAuth = base64_encode(PROXY_USER . ":" . PROXY_PASS);+ T% v2 A4 w2 N9 N! T
2 t4 h# m" l" j
        // 设置 Proxy tunnel
% h7 v4 v8 P4 W4 T& z) R. v2 s, x        $tunnel = rand(1,10000);
$ Y  F! {1 [5 o+ @5 L6 P
$ h: ?! w& d6 R. l* y4 r# ]9 \( g        $headers = implode("\r\n", [
9 P5 _. \1 q- Q            "Proxy-Authorization: Basic {$proxyAuth}",
; ^: t$ y+ I) T            "Proxy-Tunnel: ${tunnel}",( S/ n6 }# b/ K& s+ A! e  ^$ Q
        ]);
: ~# Y, s( I& R9 {- Z: V4 e0 P8 j        $sniServer = parse_url($urls, PHP_URL_HOST);$ y7 j; c8 a  p6 o) b5 f
        $options = [/ p" h& b) @9 @3 m  e
            "http" => [2 a% s8 |- ^1 |  E% T4 N9 U8 {
                "proxy"  => PROXY_SERVER," j/ p* }1 i4 x
                "header" => $headers,- d7 H3 D+ i5 f
                "method" => "GET",
: o* y6 l/ \) F' b; t4 `( y  x                'request_fulluri' => true,* m! ?( i9 B' W( X
            ],
. m, h/ s8 g* L8 o! t, d; n! x            'ssl' => array() z9 v7 ?9 {9 x' ]' ]- o3 n* j
                    'SNI_enabled' => true, // Disable SNI for https over http proxies/ a( @8 V# B0 s+ H8 s2 [" ]( L
                    'SNI_server_name' => $sniServer
+ H6 e* }8 H8 t1 R: Q) P9 F9 G            )0 s. z/ S, X5 j( h& a" O- a$ O
        ];" T' H8 Z; G1 o$ D3 H: e
        print($url);
$ n- O7 E7 U, S- x! d6 d1 N        $context = stream_context_create($options);4 ^3 r  o) ^5 G  P4 _2 V  k7 J( t
        $result = file_get_contents($url, false, $context);1 B/ y$ w) g, E/ C( Z1 H
        var_dump($result);
8 t& e! X$ H, [; x" @" C  g1 L' i4 S: r* \
        // 访问 HTTPS 页面
1 U* S# o( b4 K; A; @( \        print($urls);
* i; }1 a4 |1 ?        $context = stream_context_create($options);
# m5 O0 ]. W) \( M9 B1 u3 t        $result = file_get_contents($urls, false, $context);4 G3 b- B( o* D! m
        var_dump($result);
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|帮助|古城IT技术联盟 ( 鲁ICP备06030014号 )

GMT+8, 2024-4-28 19:33 , Processed in 0.097720 second(s), 8 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表