Classic: learning dynamic web page PHP skills common Title summary

Source: Internet
Author: User
1: Why can't I get the variable I post the data name to another webpage on one webpage? why can't I get any value when I output $ name? In versions later than PHP4.2, the default value of reGISter_global is off. if you want to get the variable submitted from another page: Method 1: in PHP. I

1: Why can't I get the variable?

Why can't I get any value when I output $ name when I POST data name to another webpage?

In versions later than PHP4.2, the default value of reGISter_global is off.
To get the variables submitted from another page:

Method 1: Find register_global in PHP. ini and set it to on.
Method 2: Put the extract ($ _ POST); extract ($ _ GET) at the top of the receiving webpage; (pay attention to extract ($ _ SESSION) session_Start () is required ()).
Method 3: Read the variable $ a =$ _ GET ['A']; $ B =$ _ POST ['B'] and so on one by one. this method is troublesome but safe.

2: debug your program

You must know the value of a variable at runtime. In this case, create a debug. php file with the following content:

PHP code:

<? PHP
Ob_Start ();
Session_Start ();
Echo '<pre> ';

Echo 'The _ GET variables obtained on this page are :';
Print_R ($ _ GET );

Echo 'The _ POST variables obtained on this page are :';
Print_R ($ _ POST );

Echo 'The COOKIE variables obtained on this page are :';
Print_R ($ _ COOKIE );

Echo 'The _ SESSION variables obtained on this page are :';
Print_R ($ _ SESSION );

Echo '</pre> ';
?>

Then in php. set in ini: export de_path = 'C:/php', and debug. php is placed in this folder, and you can include this file in each web page to view the variable name and value.

3: How to apply the session

All session-related functions must call session_start ();

It is very simple to pay for the session, such:

PHP code:

<? Php
Session_start ();
$ Name = 'This is a Session example ';
Session_Register ('name'); // do not write it as Session_Register ('$ name ');
Echo $ _ SESSION ['name'];
// After $ _ SESSION ['name'] is 'this is a Session example'
?>

After php4.2, you can consider the session to be paid directly:

PHP code:

   <?PHP
   Session_Start();
   $_SESSION['name']='value';
   ?>

You can cancel the session as follows:

PHP code:

   <?php
   session_start();
   session_unset();
   session_destroy();
   ?>

There is a BUG in canceling a session variable above php4.2.

Note:

1: no output is allowed before Session_Start () is called. for example, the following is incorrect.
========================================================== =
1 line
2 rows and 3 rows Session_Start (); // The output is already in the first row.
4 rows .....
5 rows?>
========================================================== =

Tip 1:

Any representation '........ headers already sent .......... ', that is, the information output to the browser before Session_Start. the output is normal (the COOKIE will also display this error, and the cause of the error is the same)

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.