2015-02-07 123 views
1

我想從這個香草php中調用codeigniter方法。將十六進制作爲參數傳遞失敗

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,我得到了一個空白屏幕。爲什麼會出現這種情況?我有錯誤報告。理由可能是我作爲參數傳遞的十六進制數。

+0

你看到什麼,如果開放'的http://本地主機/應用/歡迎/進入'瀏覽器/? – Alex 2015-02-07 22:05:54

+0

Nope.Also當我打開'的http://本地主機/應用/首頁/項/ 613A313A7B733A343A2276617273223B613A323A7B733A333A226F6E65223B733A353A2268656C6C6F223B733A333A2274776F223B733A353A22776F726C64223B7D7D'我什麼也看不到 – user3272483 2015-02-07 22:11:54

+0

因此,如果沒有什麼 - 沒有什麼。爲什麼你使用另一個鏈接?您的CI實例安裝在哪裏? 'app'還是'Qplatform'?先準備好瀏覽器。 – Alex 2015-02-07 22:14:37

回答

0

我用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); 
    */ 
    }