Troubleshoot issues with PHP include parameters

Source: Internet
Author: User
Troubleshooting PHP include Parameters

PHP include can load an external PHP file whose parameters are a file name, and since it is a file name, it cannot be taken with parameters.

PHP, if the include loaded file must take parameters, there is only one way, that is, this parameter is a full path URL address.

For example:

include " http://localhost/aaa.php?id=1 "; That's right
Include "aaa.php?id=1"; Error

In fact, the original meaning is only used to load an external file into the current file, and does not explain the code. So the band parameter doesn't seem to make sense.
such as the following code (1.php):
$a = "123";
Include "aaa.php";

To receive the value of the variable $ A with aaa.php, just call it directly in the aaa.php, for example aaa.php code reads:
echo $a;

This executes 1.php, which will output a value of $ A: 123

However, there is definitely a need for a problem, and since we are asking for the include parameter, it is certainly not just that you want to use the variables in the loader file as simple in the loaded file.

The current requirements are:
You want to include different pieces of code in the same file, depending on the parameters.

Based on the above requirements, my workaround is to:
Write the code in the loaded file (assuming aaa.php) as a function, for example:
Function ABC ($x)
{
$returnValue;
Switch ($x)
{
Case 1:
$returnValue = "Apple";
Case 2:
$returnValue = "banana";
Case 3:
$returnValue = "Carambola";
}
}

This is then written in the main file (assuming 1.php):

Include "aaa.php";
Echo ABC (1); Output: Apple
Echo ABC (2); Output: Banana
Echo ABC (3); Output: Carambola

In fact, according to the above method, in the final analysis, with the previous said directly using the variables in the main file, there is no big difference, but the advantage is that regardless of how the variables in your master file change, This function in aaa.php does not need to be changed and can be used in other files as well.

In this way, the difference between the direct use of the variables in the main file and the functions placed in the main file is obvious!

Original: Thousand Snow network http://www.ayinsky.com

Here is a summary of some of the experiences I have encountered in my own use: Using ReadFile ("Http://XXXX/example.php?name=valude"); can pass files with parameters ~ ~

  • 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.