Faqts : Business : Programming : Shopping For You : PHP : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

20 of 21 people (95%) answered Yes
Recently 7 of 7 people (100%) answered Yes

Entry

Is there any way to maintain a global variable which will be accessible from all scripts?

Aug 23rd, 2009 04:10
Joe Bloggs, Praveen Kumar Kukkapalli, Rob Garth, Ben Munoz, Matt Gregory, Vshal Seth,


You can assign your value to $_GLOBAL array so that that value will be
available with in the application.

$GLOBALS['x'] = "Hi";

Then you can access the value of 'x' with in your application.


There are only 3 ways of doing this.

Create an environment variable for your scripts.
Save the value to a file, (like an INI file)
Save the value to a database.

PHP does not store any variables between scripts because each script 
has a unique run id and memory is released after execution.

-----------------------------------------------------

If you need to pass variables from one script to another you can
append it to the URL:
<a href="script.phtml?variable=value">link</a>

Or you can use a hidden input in a form:
<form action="script.phtml">
<input type=hidden name=variable value=value>
<input type=submit>
</form>

Note: you can't do this: <form action="script.phtml?variable=value">

The downside: it can get hairy with many variables.

If you have PHP4, you definitely want to look into session functions.

-----------------------------------------------------

If PHP is running on a unix host - you should be able to easily set a
shell variable and make a system call to grab when you need it.

======================================

http://www.attorneyslawyersdirectory.com
http://www.findattorneyslawyers.com
http://www.goodlawyersattorneys.com
http://www.professionallawyersattorneys.com
http://www.bestprofessionallawyers.com
http://www.americalawyersattorneys.com
http://www.availablelawyers.com
http://www.lawyersattorneyslist.com
http://www.lawyersattorneysfirm.com
http://www.originallawyers.com
http://www.lawyersgulf.com
http://www.lawyersband.com
http://www.lawyersdatacenter.com
http://www.lawyerstigers.com
http://www.lawcliff.com
http://www.tidylawyers.com
http://www.lawyersblock.com
http://www.californialawyersattorneys.com
http://www.chicagoattorneyslawyers.com
http://www.goodcalifornialawyers.com
http://www.lawyersattorneysfaqs.com
http://www.divorceattorneyslawyers.com
http://www.duiattorneyslawyers.com
http://www.personalinjurylawyerslist.com
http://www.injurylawyersattorneys.com
http://www.dwilawyersattorneys.com
http://www.healthbigboss.com
http://www.healthdohealth.com
http://www.healthcass.com
http://www.healthsilence.com
http://www.healthpicnic.com
http://www.blackmesothelioma.com
http://www.affordablelawyersattorneys.com
http://www.pickarticles.com
http://www.bloodyarticles.com
http://www.healthment.com
http://www.healthbyhealth.com
http://www.ehealthebooks.com
http://www.bestproductsofhealth.com
http://www.dietlosingweight.com
http://www.americanehealth.com
http://www.healthydepartment.com
http://www.medicalehealth.com
http://www.healthservicescenter.com
http://www.ehealthenews
http://www.ehealthdept.com
http://www.benefitshealthcenter.com
http://www.toplawyersattorneys.com 
http://www.healthxhealth.com
http://www.mesotheliomakiller.com
http://www.healthinhealth.com
http://www.booksyshop.com
http://www.mesotheliomaout.com
http://www.mesotheliomadown.com


======================================