2017-09-25 55 views
0
$Link = 'http://somewebsite.com/api.php?message=someMessage&user_id=' . $UserID . '&password=' . $UserPW; 
echo $Link; 
echo "<br><br>"; 

$PageResponse = file_get_contents($Link); 

隐私我不能发布一个工作示例,但是这是我遇到的问题。PHP file_get_contents在URL中更改apersand

当我回声$链接它返回:

http://somewebsite.com/api.php?message=someMessage&user_id=redacted&password=redacted 

不过的file_get_contents回报和错误,看起来像这样:

Warning: file_get_contents(http://somewebsite.com/api.php?message=someMessage&amp;user_id=redacted&amp;password=redacted): failed to open stream: No connection could be made because the target machine actively refused it. in C:\wamp64\www\hello.php on line 14 

,如果你会发现,它正在改变“& “字符&amp;打破了网址。有没有简单的方法来解决这个问题?

+2

这不是一个错误,它是一个功能 – Calimero

+0

您是否在使用'file_get_contents'之前尝试过'html_entity_decode'这个url字符串?否则'str_replace'会有帮助。 – Kapparina

+0

已尝试解码并替换。转换仍然存在 – kamelkid2

回答

0

您可以制作一组数据。将其序列化为字符串。 现在我们应该使用openssl_encrypt和openssl_decrypt。

你可以这样做:

$password   = "EaaJgaD0uFDEg7tpvMOqKfAQ46Bqi8Va"; 
$data    = [ 
    'message' => 'someMessage', 
    'user_id' => '111', 
    'password' => 'paaa' 
]; 
$string_to_encrypt = serialize($data); 

$encrypted_string = openssl_encrypt($string_to_encrypt, "AES-128-ECB", $password); 
//print_r($encrypted_string); 
$_SESSION["encrypted_value"] = $encrypted_string; 

现在你的加密数据对会话,以便您可以从您的网站的任何地方得到它。 现在得到你的数据吧

$encrypted_value = $_SESSION["encrypted_value"]; 
$decrypted_string=openssl_decrypt($encrypted_value,"AES-128-ECB",$password); 
//print_r($decrypted_string); 
$result = unserialize($decrypted_string); 
print_r($result); 

最后你会得到一个数组。

你必须要启动会话

在session_start();