构建数组后无法评估数组元素-var_dump确认元素存在 [英] Can't assess an array element after building array - a var_dump confirms element is there

查看:66
本文介绍了构建数组后无法评估数组元素-var_dump确认元素存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为外部应用程序编写一些登录代码。

I am writing some login code for an external app.

当前它正在通过GET发送信息。信息经过编码,服务器对信息进行解码,并构建为一个可用于对用户进行身份验证的解码数组。

Currently it is sending information via GET. The information is encoded, the server decodes the info and builds into a decoded array which I can use to auth the user.

问题是由于某种原因我无法执行当我知道它存在时,访问数组元素。我使用var_dump进行确认。

The issue is for some reason I can't access the array element, when I know it's there. I use a var_dump to confirm.

error_reporting(E_ALL);

function getNonDecodedParameters(& $a) {
  foreach (explode ("&", $_SERVER["QUERY_STRING"]) as $q) {
    $p = explode ('=', $q, 2);
    $a[$p[0]] = isset ($p[1]) ? $p[1] : '';
  }  
}

function decode_array(&$encyrptArray, &$outputArray) {

    foreach($encyrptArray as $encrpyKey=>$encrpyValue) {
        $newKey = decode_my_mt4_string($encrpyKey);
        $newVal = decode_my_mt4_string($encrpyValue);

        $outputArray[$newKey] = $newVal;                
    }   
}

//init arrays
$inputs = array();
$decoded = array();

//manually build array from query string
//bypassing $_GET because $_GET does auto urldecode()
getNonDecodedParameters($inputs);

//decode data into new array
decode_array($inputs, $decoded);

//var dump
echo '<pre>';
var_dump($inputs);
echo '<br />';
echo 'Decoded array';
echo '<br />';
var_dump($decoded);
echo '</pre>';

//try access specific array element
printf('$decoded["cname"] = %s', $decoded['cname']);

var_dump显示此方法有效,但是由于某些原因,当我直接调用该元素时,php错误抛出并说它不存在?

The var_dump shows this is working, but for some reason when I call the element directly, a php error is thrown saying it doesn't exist???

array(3) {
  ["d3JfbG9naW4A"]=>
  string(12) "dGVzdHVzZXIA"
  ["cGFzcwA%3D"]=>
  string(12) "dGVzdHBhc3MA"
  ["Y25hbWUA"]=>
  string(14) "REFaV0FSRQA%3D"
}

Decoded array
array(3) {
  ["wr_login"]=>
  string(9) "testuser"
  ["pass"]=>
  string(9) "testpass"
  ["cname"]=>
  string(8) "DAZWARE"
}

Notice: Undefined index: cname in /home/website/test2.php on line 58
$decoded["cname"] =

我真的想不出为什么它不起作用。

I really can't think of any reason why this isn't working. Couldn't this be an issue with the server?

推荐答案

谢谢大家,

只是为了给您时间,并跟进这里发生的事情。

Just to give you back the time and follow up what happened here.

变量名中的错误不是问题,只是我在这里所做的错字

The error in the variable name was not the problem, just a typo I made here.

我正在使用base64进行编码,并将该数据发送到php脚本。当我使用base64_decode()时,它会吐出正确的字符串,但也会吐出损坏所有变量名的垃圾字节。

I was encoding with base64 and sending that data to the php script. When I used base64_decode(), it would spit out the right string, but also junk bytes that was corrupting all the variable names.

问题是base 64编码器不好

The problem was a bad base 64 encoder from the external program I was using.

谢谢大家花时间在这里帮助我。

Thank you all for taking the time to help me here.

这篇关于构建数组后无法评估数组元素-var_dump确认元素存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆