将十六进制作为参数传递失败


Passing hex as a parameter fails

我正试图从vanilla php中调用一个代码点火器方法,如下所示。

get.php

<?php
$options = array(
    'vars' => array(
        'one'   => 'hello',
        'two'   => 'world'
    )
);
function strToHex($string){
    $hex = '';
    for ($i=0; $i<strlen($string); $i++){
        $ord = ord($string[$i]);
        $hexCode = dechex($ord);
        $hex .= substr('0'.$hexCode, -2);
    }
    return strToUpper($hex);
}

$p1 = $options["vars"]["one"];
$p2 = $options["vars"]["two"];
$en = serialize($options);
$tohex = strToHex($en);
try{
echo file_get_contents("http://localhost/app/welcome/entry/".$tohex);
$json = file_get_contents("http://localhost/app/welcome/entry/".$tohex,true);
if ($json === false) {
    echo 'Request with id'.' '.rand(5667789,790637738).' '.'was not successful.This incident was logged.';
}
}
catch(Exception $e){
echo $e->getMessage();
}
?>

这是我的代码点火器方法

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
    public function index()
    {
        $this->load->view('welcome_message');
    }
    public function hexToStr($hex){
    $string='';
    for ($i=0; $i < strlen($hex)-1; $i+=2){
        $string .= chr(hexdec($hex[$i].$hex[$i+1]));
    }
    return $string;
    }
    public function entry($in){
    $in = $this->uri->segment(3);
    $arr = hexToStr($in);
    $array = unserialize($arr);
    print_r($array);
    /**
    $p1 = $arr["vars"]["one"];
    $p2 = $arr["vars"]["two"];
    redirect('welcome/'.$p1/$p2);
    */
    }
    public function hello(){
    echo 'connected';
    }
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

当我运行get.php时,我得到一个空白屏幕。为什么会这样?。我在上有错误报告。原因可能是我作为参数传递的十六进制吗?。

我使用了hex2bin函数,现在我的代码可以像预期的一样工作

public function entry($in){
    $in = $this->uri->segment(3);
    $arr = hex2bin($in);
    $array = unserialize($arr);
    $p1 = $arr["vars"]["one"];
    //print_r($array);
    $p1 = $array["vars"]["one"];
    echo $p1;
    /**
    $p1 = $arr["vars"]["one"];
    $p2 = $arr["vars"]["two"];
    redirect('welcome/'.$p1/$p2);
    */
    }