Global variables in php are referenced in multiple files

Source: Internet
Author: User
In php, global variables are referenced in multiple files:
Can I define A global variable in the php file, reference and assign values to the B php file, and reference and access the C php file? it seems I can't test it. Value assignment in B. only content in A can be seen in C, and the value changed by B cannot be seen.

Thank you!


Reply to discussion (solution)

Of course. The premise is that
C. php

include 'A.php';include 'B.php';
Or
B. php
include 'A.php';

C. php
include 'B.php';

You didn't reference B php in C php, right?

I wrote a simple example to illustrate my thoughts:
A. php

 ";?>


B. php
 The value of var_global in Unit B is: ". $ var_global; echo"
Jump to view results ";?>


C. php
 The value of var_global in Unit C is: ". $ var_global;?>


The execution result is:

A. php:->
Jump to B assignment
B. php->
The value of var_global in Unit B is assigned by B.
Jump to view results
C. php->
Jump to B assignment

The value of var_global in Unit C is:

That is, the value obtained in C is null, not the value assigned by B"

Of course. The premise is that
C. php

include 'A.php';include 'B.php';
Or
B. php
include 'A.php';

C. php
include 'B.php';

My idea is to define some global variables in A like C, and change them through the process assignment in B, the changed global variables can be used in C and other php units without SESSION. Is it feasible?
The entire include sequence should be changeable, but there is no such reference relationship between B and C, which is not clearly written.

You didn't reference B php in C php, right?
And sometimes C. php cannot include B. php, such
B is a login page
C is another business page. log on to B and mark it in C.

That's not acceptable!
How does B. php be executed if you do not reference B. php in C. php?

If the link is not contained, you must pass the parameter or use session.

The unreasonable design, why do we need to go around like this.

That's not acceptable!
How does B. php be executed if you do not reference B. php in C. php?

If the link is not contained, you must pass the parameter or use session.
Take logon as an example. A has A logon success sign $ login, and B is responsible for logging in. if the logon succeeds, $ login = "success". in C, no execution is performed by B, it is to judge whether $ login is equal to "success". if not, it does not work.
That is, we can only use sessions or cookies?

The unreasonable design, why do we need to go around like this.
I have been using C. I am a beginner in php. I am learning which usage of C is different from that of php.

Yes. in this case, session/cookie is the best choice.

Yes!


That's not acceptable!
How does B. php be executed if you do not reference B. php in C. php?

If the link is not contained, you must pass the parameter or use session.
Take logon as an example. A has A logon success sign $ login, and B is responsible for logging in. if the logon succeeds, $ login = "success". in C, no execution is performed by B, it is to judge whether $ login is equal to "success". if not, it does not work.
That is, we can only use sessions or cookies?

You use C to write a desktop program, and the interaction with the user is completed during the running of the program.
Website programs run intermittently and do not store the site (or store the site)

Thank you very much for your enthusiastic help.

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.