-1

我会请是否有人可以帮助我。

我有以下测试表单('form.html'),如果我使用“提交按钮”,我可以将“用户名”和“位置 ID”变量传递给下一个表单,在本例中为“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>

但是,当我加载表单时,我收到以下错误:

警告:session_start() [function.session-start]:无法发送会话缓存限制器 - 已在 /homepages/2/d333603417 中发送标头(输出开始于 /homepages/2/d333603417/htdocs/development/form.php:2) /htdocs/development/form.php 在第 3 行

我对“会话变量”不太熟悉,因为我只是在学习。但我只是想知道是否有人可以看看这个并让我知道我哪里出错了。

非常感谢和问候

4

3 回答 3

1

session_start() 应该在任何输出到浏览器之前被调用,所以把它放在发送任何东西之前。输出是从 form.php 文件发送的。

于 2012-04-18T14:42:26.417 回答
1

似乎在你的 php 页面的某个地方你有 session_start(); 在其他操作后调用(如打印 hmtl)。

始终将 session_start() 作为 php 页面中的第一条指令

于 2012-04-18T14:42:44.657 回答
1

放置以下内容:

session_start(); 

在gallery.php 的顶部,而不是form.html。此外,除非您使用 javascript 在单击链接时提交表单,否则您不能以这种方式提交表单,请参见此处:http ://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml 。此外,您的表单上没有打开 <form> 标记。

于 2012-04-18T14:43:15.950 回答