关于php:将带有多个变量的URL作为参数发送到另一个页面 | 珊瑚贝

Sending a URL with multiple variables as a parameter to another page


我有一个 Javascript 页面,它将数据发送到一个 PHP 页面。该数据是具有不同查询字符串的 URL,例如:

1
2
3
4
5
6
7
8
9
10
11
    var localURL =“http://localhost/app/proxy.php?data=http://myserver.com/game.php?type=loadgame&userInfoName=AA&userPwd=AA&nocache=0.8046834595784704”

    $.ajax({
        url: localURL,
        beforeSend: function (xhr) {
            alert(‘beforesend’);
        },
        success: function (data) {
            alert(‘success: ‘ + data);
        }
    });

查询字符串变量的数量可以变化,所以我不能用ajax函数的data参数发送。如果我对数据变量 ($_GET[\\’data\\’];) 执行 GET,我会得到以下结果:

http://myserver.com//game.php?type=loadgame

而我想得到的是:

http://myserver.com/game.php?type=loadgame

  • 好吧,您将其发送到 proxy.php 并且 URL 正在使用 game.php;您确定 proxy.php 正确转发查询字符串吗?


你必须逃跑才能得到一个有效的 url:

1
2
var data = escape(‘http://myserver.com/game.php?type=loadgame&userInfoName=AA&userPwd=AA&nocache=0.8046834595784704’);
var localURL =“http://localhost/app/proxy.php?data=” . data;

您缺少的是 localUrl 变量中的 URL 转义。

应该是这样的:

1
var localURL =“http://localhost/app/proxy.php?data=http%3A%2F%2Fmyserver.com%2Fgame.php%3Ftype%3Dloadgame%26userInfoName%3DAA%26userPwd%3DAA%26nocache%3D0.8046834595784704″

如果你用javascript构造localURL,使用escape()函数


n


这是浏览器看到的:

1
2
3
4
5
6
7
8
9
http://localhost/app/proxy.php?

data=http://myserver.com/game.php?type=loadgame => param 1

&userInfoName=AA => param 2

&userPwd=AA => param 3

&nocache=0.8046834595784704 => param 4

所以你应该转义字符串”http://myserver.com/game.php?type=loadgame

  • 值得更新您的答案,说 $.URLEncode 需要插件才能工作。


1
var localURL =“http://localhost/app/proxy.php?data=” + encodeURIComponent(“http://myserver.com/game.php?type=loadgame&userInfoName=AA&userPwd=AA&nocache=0.8046834595784704”);

来源:https://www.codenong.com/7442884/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9102.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?