一、表单传递

----------------------page1.htm-----------------


PHP:--------------------------------------------------------------------------------
<html>
<form name="form1" method="post" action="page2.php" >
<input type="submit" name="Submit" value="提交">
<input type="hidden" name="a" value="hello">
</form>
</html>

--------------------------------------------------------------------------------


------------------------page2.php---------------------

PHP:--------------------------------------------------------------------------------

<?
$a=$_POST["a"]; //$a的值为“hello”
?>

--------------------------------------------------------------------------------


二、超链接传递:
-------------------page1.php----------

PHP:--------------------------------------------------------------------------------

<?
$a="hello";
?>
<a href=page2.php?a=<? echo $a ?>>转到</a>

上面是在html中的,

在php中这样:注意变量要在双引号中。

<?php

$host_name=$arr[$a-1+$page_size*($page-1)]['display_name'];
echo "<td>".'<a href='."host_click.php?host_name=$host_name name='host_click' style='text-decoration:underline;'>".$host_name."</a></td>"; 

?>



--------------------------------------------------------------------------------


-------------------page2.php-------------------

PHP:--------------------------------------------------------------------------------

<?
$a=$_GET["a"]; //$a的值为“hello”
?>

--------------------------------------------------------------------------------


三、重定向传递:
1、
-------------------page1.php----------

PHP:--------------------------------------------------------------------------------

<?
ob_start();
$a="hello";
header("Location:page2.php?a=".$a);
ob_end_flush();
?>

--------------------------------------------------------------------------------


或2、
----------------------------------------

PHP:--------------------------------------------------------------------------------

<?
ob_start();
$a="hello";
echo"<script>Location='page2.php?a=".$a."';</script>");
ob_end_flush();
?>

--------------------------------------------------------------------------------

或3、
----------------------------------------

PHP:--------------------------------------------------------------------------------

<?
ob_start();
$a="hello";
echo"<META HTTP-EQUIV='Refresh'  CONTENT='0;URL=page2.php?a=".$a."'>";
ob_end_flush();
?>

--------------------------------------------------------------------------------

-------------------page2.php-------------------

PHP:--------------------------------------------------------------------------------

<?
$a=$_GET["a"]; //$a的值为“hello”
?>

--------------------------------------------------------------------------------


四、用COOKIE传递的方法:

-------------page1.php-----------------------
<?
$a="hello";
setcookie("a","$a");
?>

-------------page2.php-----------------------
<?
$a=$_COOKIE["a"];
echo $a;
?>

五、用SESSION传递的方法:
-------------page1.php-----------------------
<?
session_start();
session_register("a");
$a="hello";
?>

-------------page2.php-----------------------
<?
$a=$_SESSION["a"];
echo $a;
?>