Home  >  Article  >  Backend Development  >  Four ways to pass parameters in PHP

Four ways to pass parameters in PHP

WBOY
WBOYOriginal
2016-07-28 08:28:231538browse

test1 interface:

<html>
<head>
<title>testPHP</title>

<meta http-equiv = "content-type" content = "text/html; charset = utf-8"/>

</head>
<body>
<?php
	
	//第一种设置传参方式,通过cookie
	setcookie(&#39;my&#39;,&#39;yefeng&#39;);
	
	//第二种传参方式,通过设置服务器session值传递参数
	session_start();
	$_SESSION["temp"] = array(&#39;456&#39;,&#39;789&#39;);
	
	
	$test = "我是一个测试变量";	
	
?>

<div id = "test1" style = "height:10%; border:1px solid red">
	//第一种传参方式
</div>

<div id = "test2" style = "height:10%; border:1px solid red; margin-top:5%">
	//第二种传参方式
</div>


<div id = "test3" style = "height:10%; border:1px solid red; margin-top:5%">
//第三种传参方式
	<form action = "test2.php" method = "post">
			
			<input type = "text" name = "my"/>
			
			<input type = "submit" name = "submit" value = "提交" />
		
	</form>	
</div>



<div id = "test4" style = " height:10%; border:1px solid red; margin-top:5%">
	<a href = "<?php echo"test2.php?urlValue=".$test4?>">
	第四种传参方式
	</a>
</div>
	
</body>
</html>

test2 interface:

<html>
<head>
<meta charset = &#39;utf-8&#39; />

<?php

	

	$test = $_COOKIE[&#39;my&#39;];
	
	echo $test;
	echo &#39;<br/>';
	session_start();
	
	for($i = 0; $i < 2; $i ++){
		
		echo $_SESSION[&#39;temp&#39;][$i].&#39;<br/>';
	}
	
	$testForm = $_POST['my'];
	
	echo "表单参数传递".$testForm;
	
	echo "第四种传参值".$_GET['urlValue'];

?>

</head>
<body></body>
</html>

The above introduces the four methods of passing parameters in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn