2012-07-28 123 views
-5

我得到了這些名爲php的文件:clients,type和info。通過鏈接訪問PHP變量

想象一下像Facebook這樣的網站。

你有:www.site.web/profile?= 232,你點擊一個相冊,現在你有www.site.web/profile?= 232 & album = 10,所以你點擊你有的照片www.site.web/profile.php?= 232 & album = 10 & photo = 1。

我想了解你,他們做this..keeping是「profile.php」

+3

我不知道你在問什麼。 – David 2012-07-28 02:06:03

+0

你在問如何通過URL傳遞參數嗎? – dykeag 2012-07-28 02:09:33

+0

嗨,對不起,我剛剛看到如何接受awirs:s – user1148875 2012-07-28 02:14:46

回答

2

我想你在找什麼是使用隱藏的輸入,讓您的變量從一個頁面傳遞到頁面。

使用類似這樣的形式:

<form method='get'> 
    <input type='hidden' name='client' value='1'> 
    // Your other inputs 
</form> 

這樣,當你得到一個輸入,你可以使用一些簡單的PHP代碼保持從頁傳遞到頁把它撿起來從URL和顯示器它再次根據需要。

編輯:(進一步說明)

當你通過URL從一個網頁傳遞到另一個數據可以用一些簡單的PHP代碼,看看是否有存在進一步把它傳遞 - 這樣的:

<?php //page1.php 

if(isset($_GET['user'])) 
{ 
    $user=htmlspecialchars($_GET['user']); 
} 

if(isset($_GET['photo'])) 
{ 
    $photo=htmlspecialchars($_GET['photo']); 
} 

// Check for anything else you want as needed. 

?> 

那麼,究竟讓你的鏈接時,你可以這樣做:

<?php 

    $baseAddress="<a href='thePageIwant.php?thisVar=3"; 
    if(isset($user)) 
    { 
     $baseAddress.="&user=".$user; 
    } 

    if(isset($photo)) 
    { 
     $baseAddress.="&photo=".$photo; 
    } 
    // Add any other variables as needed 

    $baseAddress.="'> 
?> 

在網頁的HTML輸出部分,你可以使用這個:

<p>Some text and then a link <?php echo $baseAddress;?>Your Link Text</a></p> 

而且您的鏈接將與其他所有通過URL傳遞的變量一起出現。在這種情況下,如果用戶被傳遞到頁面ID爲4,和照片傳遞到頁面ID爲6,HTML輸出將是:

<p>Some text and then a link <a href='thePageIwant.php?thisVar=3&user=4&photo=6'>Your Link Text</a></p> 

如果只有用戶是在URL過去了,沒有photo=6輸出會是這樣的:

<p>Some text and then a link <a href='thePageIwant.php?thisVar=3&user=4'>Your Link Text</a></p> 
+0

不可以。想象一下像Facebook這樣的網站。你有www.site.web/profile?= 232,你點擊一個相冊,現在你有www.site.web/profile?= 232&album = 10,所以你點擊一張你有www.site.web/profile的照片.PHP?= 232&專輯= 10&照片= 1。我想了解你他們做這個..保留「profile.php」 – user1148875 2012-07-28 02:45:22

+0

爲你增加額外的PHP解決方案。 – Fluffeh 2012-07-28 02:59:05

+0

來吧,讓他們來吧,一個*逆轉*這裏會是額外的甜蜜:) – Fluffeh 2012-07-28 10:36:59