2015-01-06 42 views
0

我試着去構造一個URL,如:

https://theserver/career/pathway?path=3&edu=4&cert= 

這裏的首要問題是$message變種正在失去的$pathval值,$edval$certval當填充到數組ALA $data(如下所示)

當使用最後一個碼塊

else if ($action == "send") { 
    //added 
    #pathway var 
    var_dump($_SESSION); 
    $pathval = $_SESSION['pathid']; 
    $edval = $_SESSION['edid']; 
    $certval = $_SESSION['certid']; 

    var_dump($pathval); 
    var_dump($edval); 
    var_dump($certval); 

    $data = array(
     "path"=>$pathval, 
     "edu"=>$edval, 
     "cert"=>$certval 
    ); 

    var_dump($data); 


    $server_prefix = 'https://'; 
    $server_address = $_SERVER['SERVER_ADDR']; 

    #$fullurl = $server_prefix.$server_address."/career/pathway?ed=".$edval; 

    // Send the email 
    $name = isset($_POST["name"]) ? $_POST["name"] : ""; 
    $email = isset($_POST["email"]) ? $_POST["email"] : ""; 
    $subject = isset($_POST["subject"]) ? $_POST["subject"] : $subject; 
    $message = $server_prefix.$server_address.'/career/pathway?'.http_build_query($data); 
    var_dump($message); 
    // $message = $pathval; 
    var_dump($message); 

    $cc = isset($_POST["cc"]) ? $_POST["cc"] : ""; 
    $token = isset($_POST["token"]) ? $_POST["token"] : ""; 

    // make sure the token matches 
    if ($token === smcf_token($to)) { 
     smcf_send($name, $email, $subject, $message, $cc); 
     echo "Your message was successfully sent."; 
     // echo $name . "\n"; 
     // echo $email . "\n"; 
     // echo $subject . "\n"; 
    } 
    else { 
     echo "Unfortunately, your message could not be verified."; 
    } 
} 

此輸出(該電源輸出太棒了!):

array(3) { ["pathid"]=> string(1) "3" ["edid"]=> string(1) "4" ["certid"]=> string(0) "" } string(1) "3" string(1) "4" string(0) "" array(3) { ["path"]=> string(1) "3" ["edu"]=> string(1) "4" ["cert"]=> string(0) "" } string(56) "https://theserver/career/pathway?path=3&edu=4&cert=" string(56) "https://theserver/career/pathway?path=3&edu=4&cert=" Your message was successfully sen 

電子郵件輸出爲Message: https://theserver/career/pathway?path=edu=cert

+0

你已經把'在session_start()? –

+0

這真的很奇怪。你如何輸出這些字符串? –

+0

是會話已創建,值是第一個「如果我嘗試」 – user2107529

回答

0

對不起,我不能尚未置評。

但正如@JeremiahWinsley說:

http://php.net/manual/en/function.http-build-query.php

$pathval = 3; 
    $edval = 4; 
    $certval = ''; 
    $server_prefix = 'https://'; 
    $server_address = 'website.com'; 
    $data = array('path'=>$pathval, 
     'edu'=>$edval, 
     'cert'=>$certval); 

    echo $server_prefix.$server_address.'/career/pathway?'.http_build_query($data) . "\n"; 
    echo $server_prefix.$server_address.'/career/pathway?'.http_build_query($data, '', '&'); 

輸出:

https://website.com/career/pathway?path=3&edu=4&cert= 
https://website.com/career/pathway?path=3&edu=4&cert= 

就是你要的?

您的問題phph代碼必須是這樣的:

if ($action == "send") { 
     // VALUES EXIST HERE 
     var_dump($_SESSION); 
     $pathval = $_SESSION['pathid']; 
     $edval = $_SESSION['edid']; 
     $certval = $_SESSION['certid']; 
     var_dump($pathval); 
     var_dump($edval); 
     var_dump($certval); 

     // << LOSING THE VALUES HERE >> 
     $data = array(
      "path"=>$pathval, 
      "edu"=>$edval, 
      "cert"=>$certval 
     ); 
     var_dump($data); 
     // This DOES NOT work, and outputs: `path=edu=cert` 
     $message = http_build_query($data); 
     var_dump($message); 
     // This DOES work and outputs: `3` 
     $message = $pathval; 
      var_dump($message); 
exit; 
     } 

所以現在所有這些回聲和你的PHP代碼一切都清楚了! 只是周到!

你的代碼必須是:

else if ($action == "send") { 
//added 

$pathval = $_SESSION['pathid']; 
$edval = $_SESSION['edid']; 
$certval = $_SESSION['certid']; 

var_dump($pathval); 
var_dump($edval); 
var_dump($certval); 

$data = array(
    "path"=>$pathval, 
    "edu"=>$edval, 
    "cert"=>$certval 
); 

var_dump($data); 

$server_prefix = 'https://'; 
$server_address = $_SERVER['SERVER_ADDR']; 

// Send the email 
$name = isset($_POST["name"]) ? $_POST["name"] : ""; 
$email = isset($_POST["email"]) ? $_POST["email"] : ""; 
$subject = isset($_POST["subject"]) ? $_POST["subject"] : $subject; 
$message = $server_prefix.$server_address.'/career/pathway?'.http_build_query($data); 
var_dump($message); 

$cc = isset($_POST["cc"]) ? $_POST["cc"] : ""; 
$token = isset($_POST["token"]) ? $_POST["token"] : ""; 

// make sure the token matches 
if ($token === smcf_token($to)) { 
    smcf_send($name, $email, $subject, $message, $cc); 
    echo "Your message was successfully sent."; 
} 
else { 
     echo "Unfortunately, your message could not be verified."; 
    } 
} 

,如果它的工作原理 - 你可以在`你的頁面的頂部去除剩餘的var_dump線

+0

什麼?它仍然沒有發送值 – user2107529

+0

顯示我的輸出:-) – Alex

+0

請參閱部分:「This outputs」 – user2107529