search
Homephp教程php手册[转] PHP在不同页面之间传值的三种常见模式

[转] PHP在不同页面之间传值的三种常见方式 转自: http://my.oschina.net/jiec/blog/196153 一. POST传值 post传值是用于html的form表单跳转的方法,很方便使用。例如: html form action='' method='' input type='text' name='name1' input type='hidden'

[转] PHP在不同页面之间传值的三种常见方式

转自: http://my.oschina.net/jiec/blog/196153     

 

一. POST传值

      post传值是用于html的

表单跳转的方法,很方便使用。例如:

<html>
 <form action='' method=''>
 <input type='text' name='name1'>
 <input type='hidden' name='name2' value='value'>
 <input type='submit' value='提交'>
 </form>
 </html>

  

  &【本文来自鸿网互联 (http://www.68idc.cn)】nbsp;   form中的action填入的是跳转页面的url路径,method填入post方法。form表单中的提交按钮按下后,就会把form中有name的内容都传到填入的url中,可以通过$_POST['name']获取,例如:

<?php
$a=$_POST['name1'];
$b=$_POST['name2'];
?>

  

      这里有个很方便的小技巧,在input标签中把type选为'hidden'时,这个input标签会隐藏起来,不在页面显示,但这input标签在form中,并且有name值和value值,同样会跟随提交按钮传递过去,这种隐藏标签可以传递一些不想显示出来的内容。

    二.GET传值

     GET传值是通过跟随url传递的,在页面跳转时,跟着url跳转。常用于标签的使用。例如:

<a href='delete.php?id=value'>点我跳转</a>

  

 

   跳转进入xxx.php后,就能通过$_GET['id']获取传递的值。GET方法常用于URL的目的是删除或读取某个id的php文件。

   三.SESSION传值

   SESSION是全局变量的一种,经常用于用户登陆后保存用户id之类的常用数据。一旦保存到SESSION中,其他页面都可以通过SESSION获取,SESSION的使用要开启session:

<?php
//session赋值
   session_start();
   $_SESSION['one']=value1;
   $_SESSION['two']=value2;
 
//session值的读取:
   $one = $_SESSION['one'];
    
   //session值的销毁
   unset($_SESSION['one']);
?>

  

   以上三种方式是常用方式,大家可以参考使用。

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function