2015-08-26 16 views
-1

我試圖發送user_id在url我登錄後得到的身份證符合。以下是代碼 extract($ _ POST);如何使用php在頭中發送變量值?

$result = $dbg->prepare("SELECT `p_id`,`email` FROM `complit_register_provider` WHERE `email`=:hjhjhjh AND `password`=:psspsps") ; 
         $result->bindParam(':hjhjhjh', $login_mail); 
         $result->bindParam(':psspsps', $login_password); 
         $result->execute(); 
         $rows = $result->fetch(PDO::FETCH_ASSOC); 
         $row=$result->rowCount(); 
      if($rows){ 
       $result=$result->fetch(PDO::FETCH_ASSOC); 
       $_SESSION['Uname']=$rows['email']; 
       $_SESSION['Utype']="provider"; 
       $_SESSION['Uid']=$rows['p_id']; 
     $user_id=$_SESSION['Uid']; 

header('Location: http://127.0.0.1/pages/user_index/provider/user_profile/show_own_profile.php?Show=$user_id'); 
      } 

但它不工作。顯示的網址類似。

http://127.0.0.1/pages/user_index/provider/user_profile/show_own_profile.php?Show= $ USER_ID, 它應該顯示例如像 http://127.0.0.1/pages/user_index/provider/user_profile/show_own_profile.php?Show=9 我怎樣才能做到這一點?

+0

嚴重不你看,單引號? PHP不要解析變量在單引號http://php.net/manual/en/language.types.string.php –

回答

0

任何單引號內,'',被視爲由PHP的字符串。

將其更改爲 header('Location: http://127.0.0.1/pages/user_index/provider/user_profile/show_own_profile.php?Show='. $user_id);

+0

Thx它的工作 – sanji

0

試試這個:

header('Location: http://127.0.0.1/pages/user_index/provider/user_profile/show_own_profile.php?Show='.$user_id); 
0

你必須使用

header("Location: http://127.0.0.1/pages/user_index/provider/user_profile/show_own_profile.php?Show=$user_id"); 

,而不是

header('Location: http://127.0.0.1/pages/user_index/provider/user_profile/show_own_profile.php?Show=$user_id'); 

有關單引號和雙引號,你應該看看之間的區別的詳細信息at:http://php.net/manual/en/language.types.string.php

0

正如其他人指出的那樣,您正在使用單引號'',這會導致PHP無法識別您要發送的$user_id變量。

使用雙引號""解決此問題。

header("Location: http://127.0.0.1/pages/user_index/provider/user_profile/show_own_profile.php?Show=$user_id"); 

進一步閱讀在PHP中的兩種報價之間的差異:

PHP: Strings