我想是否有人可以帮助我。
我有以下测试表单(' form.html'),如果我使用提交按钮'我可以传递用户名'和' 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>
这就是&#39; gallery.php&#39;
<?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/> ← 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/htdocs/development/form.php:2)in 第3行/homepages/2/d333603417/htdocs/development/form.php
我不太熟悉会话变量&#39;因为我只是在学习。但我只是想知道是否有人可以看看这个,让我知道我哪里出错了。
非常感谢和问候
答案 0 :(得分:1)
答案 1 :(得分:1)
似乎你的php页面中的某个地方有session_start();在其他操作之后调用(如print hmtl)。
将session_start()作为php页面中的第一条指令
答案 2 :(得分:1)
提出以下内容:
session_start();
位于gallery.php的顶部,而不是form.html。此外,除非您在点击链接时使用javascript提交表单,否则您无法以此方式提交表单,请参阅此处:http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml。此外,你没有开放&lt;形式&GT;在您的表单上标记。