PHP three common ways to pass values to different pages and _php instance of PHP and HTML transfer value problem

Source: Internet
Author: User

In project development often see the value of different pages in the Web work, this article gives you a list of three common ways.

have been in touch with PHP for several months, this article summarizes this period of time, in the programming process commonly used in 3 different page transfer value method, hope can give you reference. Have any comment also hope everybody discuss together.

A. Post Pass value

The post pass value is a method of <form> form jump for HTML, which is easy to use. For example:

  
  

The action in form fills in the URL path of the jump page, and method fills in the post methods. When the Submit button in form forms is pressed, the name in the form is uploaded to the URL that is filled in, and can be obtained by $_post[' name ', for example:

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

Here is a very handy trick, in the input tag to select the type ' hidden ', the input tag will be hidden, not the page display, but the input tag in the form, and has a name and value value, the same will follow the submit button passed past, This hidden tag can pass something that you don't want to show.

Two. Get Pass value

Get pass value is passed by following the URL, when the page jumps, follow the URL jump. Used in <a> label use. For example:

<a href= ' delete.php?id=value ' > Dot i jump </a>

After jumping into xxx.php, you can get the value passed by $_get[' id '. A Get method is commonly used for URLs to delete or read a PHP file for an ID.

three. Session Pass value

Session is a global variable, often used for users to save the user ID after logging the common data. Once saved to session, other pages can be obtained through session, the session will be used to open session:

<?php
//session assigned value
  session_start ();
  $_session[' one ']=value1;
  $_session[' two ']=value2;
Reading of Session value:
  $one = $_session[' one '];
  The destruction of the session value
  unset ($_session[' one ']);
? >

The above is a small set up to everyone listed three ways for everyone to reference, and hope you like.

The problem of passing values between PHP and HTML

This form I use form how to pass the value to PHP, the focus is how PHP to receive such data

------Solutions----------------------

Form two parameters, an action, indicating which file to pass, do not write the default to pass themselves; A method that shows how to pass it, there are two kinds of get and post

Input box plus name

The accepted file is received in $_post (POST) or $_get (get) Form. The simplest is direct var_dump ($_post) or Var_dump ($_get) and then you'll know how to call the

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.