2012-04-18 69 views
-1

我會否有人可以幫助我請。通過會話變量從一種形式到另一種鏈接

我有以下測試表單('form.html'),如果我使用'Submit Button',我可以將'username'和'locationid'變量傳遞給下一個表單,在這裏是'gallery'。 PHP的」

<form method="post" action="gallery.php"><br/><br/> 

<input type="text" name="username" value="IRHM73" /><br/><br/> 
<input type="text" name="locationid" value="1" /><br/><br/> 
<input type="submit" name="submit"/><br/><br/> 

</form> 

,這是‘gallery.php’

<?php 

$_SESSION['username']=$_POST['username']; 
$_SESSION['locationid']=$_POST['locationid']; 

?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<?php 

    $galleryPath = 'UploadedFiles/' . $_SESSION['username'] . '/' . $_SESSION['locationid'] . '/'; 

    $thumbnailsPath = $galleryPath . 'Thumbnails/'; 

    $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; 

    $descriptions = new DOMDocument('1.0'); 
    $descriptions->load($absGalleryPath . 'files.xml'); 
?> 
<head> 
    <title>Gallery</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <link href="Libraries/fancybox/jquery.fancybox-1.3.1.css" rel="stylesheet" type="text/css" /> 
    <link href="Styles/style.css" rel="stylesheet" type="text/css" /> 
    <!--[if IE]> 
    <link href="Styles/ie.css" rel="stylesheet" type="text/css" /> 
    <![endif]--> 
    <script src="Libraries/jquery/jquery-1.4.3.min.js" type="text/javascript"></script> 
    <script src="Libraries/fancybox/jquery.fancybox-1.3.1.pack.js" type="text/javascript"></script> 
    <script type="text/javascript"> 

    $(function() { $('a.fancybox').fancybox(); }); 

    </script> 
    <style type="text/css"> 
<!-- 
.style1 { 
    font-size: 14px; 
    margin-right: 110px; 
} 
.style4 {font-size: 12px} 
--> 
    </style> 
</head> 
<body style="font-family: Calibri; color: #505050; font-size: 9px; border-bottom-width: thin; margin-top: 5px; margin-left: -476px; margin-right: 1px; margin-bottom: -10px;"> 
<div align="right" class="style1"> <a href = "imagefolders.php" /> View Uploaded Images In Folder Structure <a/> &larr; View All Uploaded Images </div> 
    <form id="gallery" class="page"> 
    <div id="container"> 
    <div id="center"> 
     <div class="aB"> 
     <div class="aB-B"> 
      <?php if ('Uploaded files' != $current['title']) :?> 
      <?php endif;?> 
      <div class="demo"> 
      <input name="username" type="text" id="username" value="IRHM73" /> 
      <input name="locationid" type="text" id="locationid" value="1" /> 
      <div class="inner"> 
       <div class="container"> 
       <div class="gallery"> 
        <ul class="gallery-image-list"> 
        <?php for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) : 
          $xmlFile = $descriptions->documentElement->childNodes->item($i); 
          $name = htmlentities($xmlFile->getAttribute('originalname'), ENT_COMPAT, 'UTF-8'); 
          $description = htmlentities($xmlFile->getAttribute('description'), ENT_COMPAT, 'UTF-8'); 
          $folder = htmlentities($xmlFile->getAttribute('folder'), ENT_COMPAT, 'UTF-8'); 
          $source = $galleryPath . rawurlencode($xmlFile->getAttribute('source')); 
          $thumbnail = $thumbnailsPath . rawurlencode($xmlFile->getAttribute('thumbnail')); 
        ?> 
        <li class="item"> 
         <a class="fancybox" target="_blank" rel="original" href="<?php echo $source; ?>"><img class="preview" 
         alt="<?php echo $name; ?>" src="<?php echo $thumbnail; ?>" /></a></li> 
         <p><span class="style4"><b>Image Description:</b> <?php echo htmlentities($xmlFile->getAttribute('description'));?> <br /> 
          <b>Contained in folder:</b> <?php echo htmlentities($xmlFile->getAttribute('folder'));?> </span><br /> 
          <?php endfor; ?> 
          </li> 
         </p> 
        </ul> 
       </div> 
       </div> 
      </div> 
      </div> 
     </div> 
     </div> 
    </div> 
    </div> 
     <div class="aB-a">  </div> 
     </div> 
    </div> 
    </div> 
    </form> 
</body> 
</html> 

現在我試圖執行相同的操作,但這次通過一個鏈接,而不是一個按鈕。

我沒有改變我的「gallery.php劇本,但我的修訂格式如下:

<?php 
session_start(); 
$_SESSION['username']="username"; 
$_SESSION['locationid']="locationid"; 
echo '<a href="gallery.php">Gallery</a>'; 

?> 

<input type="text" name="username" value="IRHM73" /><br/><br/> 
<input type="text" name="locationid" value="1" /><br/><br/> 

</form> 

然而,當我打開我收到以下錯誤形式:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /homepages/2/d333603417/htdocs/development/form.php:2) in /homepages/2/d333603417/htdocs/development/form.php on line 3

我不太熟悉'會話變量',因爲我只是在學習。但我只是想知道是否有人可以看看這個,讓我知道我哪裏出錯了。

非常感謝和問候

+0

關於[Headers already sent]的100000500000問題的副本(http://stackoverflow.com/questions/2938777/headers-already-sent)錯誤 – 2012-04-18 14:43:01

回答

1

在session_start()應任何輸出到瀏覽器之前被調用,所以把它發送任何東西之前。輸出從form.php文件發送。

+0

非常感謝您的幫助。親切的問候 – IRHM 2012-04-18 14:48:27

1

它似乎在你的PHP頁面的某處你有session_start();在其他操作之後調用(如print hmtl)。

始終把在session_start()作爲第一個指令在PHP頁面

+0

這很棒@ ab_dev86。非常感謝 – IRHM 2012-04-18 14:48:58