将变量传递给其他php文档

时间:2013-01-19 05:35:03

标签: php

我正在尝试设置一个在URL中接收变量的php,然后使用该信息创建一个存折传递。

如果我手动设置变量,一切正常,但如果我使用$ _GET从URL获取数据,它将不会显示。

这是我的索引,我们是从URL加载变量。

<?php


$ac = $_GET['ac'];

$af = $ac;

$log = print_r($_SERVER,1);
$log .= print_r($_POST,1);
$log .= print_r($_GET,1);
file_put_contents('./log/'.time().'.txt', $log);

if(($_POST['time'] != '')||($_GET['update'] != ''))
  {
    require('./passkit.php');



    $Certificates = array('AppleWWDRCA'  => './certs/AppleWWDRCA.pem', 
                          'Certificate'  => './certs/Certificate.p12', 
                          'CertPassword' => 'password');


    $ImageFiles = array('images/icon.png', 'images/icon@2x.png', 'images/logo.png');

    $datostest = array( '1'  => $af, 
                          '2'  => '5', 
                          '3' => '6');  

    $data = array('./data/array.php',
                  './data/json.php',
                  './data/small.php',
                  './data/coupon.json',
                  './data/event.json',
                  './data/small.json',
                  './data/generic.json');

    if($_GET['update'] != '')
      {
        $example_data = 4;
      }
    elseif(!is_numeric($_POST['aexample']))
      {
        $example_data = rand(0,6);
      }
    else
      {
        $example_data = $_POST['aexample'];
      }


    if($example_data < 3)
      {
        include($data[$example_data]);
      }
    else
      {
        $JSON = file_get_contents($data[$example_data]);
      }


    $TempPath = './temp/';

    echoPass(createPass($Certificates, $ImageFiles, $JSON, 'passtest', $TempPath));

    m_uwait(12500);
    die();
  }

?>

以下是通行证签署过程

<?php

function PEM2DER($signature)
  {
    $signature = substr($signature, (strpos($signature, 'filename="smime.p7s"')+20));
    return base64_decode(trim(substr($signature, 0, strpos($signature, '------'))));
  }

function createPass($Certificates, $ImageFiles, $JSON, $PassName = 'pass', $TempPath = './temp/', $Debug = false)
  {
    //define pathes
    $UniquePassId  = time().hash("CRC32", $_SERVER["REMOTE_ADDR"].$_SERVER["HTTP_USER_AGENT"]);
    $ManifestPath  = $TempPath.$UniquePassId.'/manifest.json';
    $SignaturePath = $TempPath.$UniquePassId.'/signature';
    $PKPassPath    = $TempPath.$UniquePassId.'/'.$PassName.'.pkpass';

    //create temp dir
    mkdir($TempPath.$UniquePassId, 0777, true);

    //generate SHA1 hashes
    $FileHashes['pass.json'] = hash("SHA1", $JSON);
    foreach($ImageFiles as $ImagePath)
      {
        $ImageName = basename($ImagePath);
        $FileHashes[strtolower($ImageName)] = hash("SHA1", file_get_contents($ImagePath));
      }

    //save hashes as json in temp file
    $Manifest = json_encode($FileHashes);
    file_put_contents($ManifestPath, $Manifest);

    //load .p12 certificate
    $PKCS12 = file_get_contents($Certificates['Certificate']);
    $certs = array();
    if(openssl_pkcs12_read($PKCS12, $certs, $Certificates['CertPassword']) == true)
      {
        $certdata = openssl_x509_read($certs['cert']);
        $privkey = openssl_pkey_get_private($certs['pkey'], $Certificates['CertPassword']);
      }

    //sign file hashes with AppleWWDRCA certificate
    openssl_pkcs7_sign($ManifestPath, $SignaturePath, $certdata, $privkey, array(), PKCS7_BINARY | PKCS7_DETACHED, $Certificates['AppleWWDRCA']);
    $ManifestSignature = file_get_contents($SignaturePath);
    $ManifestSignatureDER = PEM2DER($ManifestSignature);

    //put files (and strings as files) in a zip archive
    $ZIP = new ZipArchive();
    $ZIP->open($PKPassPath, ZIPARCHIVE::CREATE);
    $ZIP->addFromString('signature', $ManifestSignatureDER);
    $ZIP->addFromString('manifest.json', $Manifest);
    $ZIP->addFromString('pass.json', $JSON);
    foreach($ImageFiles as $ImagePath)
      {
        $ImageName = basename($ImagePath);
        $ZIP->addFile($ImagePath, $ImageName);
      }
    $ZIP->close();

    //load pass data und delete temp files (if debug mode is off)
    $Pass['data'] = file_get_contents($PKPassPath);
    $Pass['size'] = filesize($PKPassPath);
    $Pass['name'] = $PassName;
    if(!$Debug)
      {
        unlink($TempPath.$UniquePassId.'/manifest.json');
        unlink($TempPath.$UniquePassId.'/'.$PassName.'.pkpass');
        unlink($TempPath.$UniquePassId.'/signature');
        rmdir($TempPath.$UniquePassId);
      }

    return $Pass;
  }

function echoPass($Pass)
  {
    //send http headers and zip archive content to client
    header('Pragma: no-cache');
    header('Content-type: application/vnd.apple.pkpass');
    header('Content-length: '.$Pass['size']);
    header('Content-Disposition: attachment; filename="'.$Pass['name'].'.pkpass"');
    echo $Pass['data'];
  }

?>

最后,我在这里使用这些变量。

<?php



$PassStyle = "boardingPass";

$JSON = '{
  "authenticationToken": "vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc",
 "foregroundColor" : "rgb(255, 255, 255)",
  "backgroundColor" : "rgb(27, 66, 152)",
  "labelColor" : "rgb(108, 173, 223)",
  "barcode": {
    "format": "PKBarcodeFormatQR",
    "message": "'.hash("SHA256", time().rand(0,2000000000)).'",
    "messageEncoding": "iso-8859-1"
  },
  "description": "Random '.$PassStyle.' Demo Pass",
  "foregroundColor": "rgb(251, 251, 251)",
  "formatVersion": 1,
  "'.$PassStyle.'": {
    "primaryFields": [
      {
        "key": "number",
        "value": "'.$datostest['1'].'"
      }
    ]
  },
  "logoText": "passkit.php",
  "organizationName": "Apple Inc",
  "passTypeIdentifier": "pass.com.apple.demo",
  "serialNumber": "8j23fm3",
  "teamIdentifier": "123ABCDEFG"
}';

?>

希望你能提供帮助。无法理解为什么它可以在手动分配变量时起作用,如果从URL加载则不行。

由于

1 个答案:

答案 0 :(得分:0)

查看上面发布的代码太多了,我觉得很难检查你的问题... 根据问题,我猜你无法访问获取值。 让我告诉你如何运作......

<a href="filename.php?value='what_you_want_to_pass'">

and at your page...

$value = $_GET['value'];

这是实际的语法,只需检查您是否已通过链接中的值...