13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Temporarily Altering the Runtime Environment<br />

529<br />

Identifying the Script Owner<br />

You can find out the user who owns the script being run with a call to the<br />

get_current_user() function, as follows:<br />

echo get_current_user();<br />

This information can sometimes be useful for solving permissions issues.<br />

Finding Out When the Script Was Modified<br />

Adding a last modification date to each page in a site is a fairly popular thing to do.<br />

You can check the last modification date of a script with the getlastmod() (note the<br />

lack of underscores in the function name) function, as follows:<br />

echo date(‘g:i a, j M Y’,getlastmod());<br />

The function getlastmod() returns a Unix timestamp, which you can feed to date(),<br />

as done here, to produce a human-readable date.<br />

Temporarily Altering the Runtime Environment<br />

You can view the directives set in the php.ini file or change them for the life of a single<br />

script.This capability can be particularly useful, for example, in conjunction with the<br />

max_execution_time directive if you know your script will take some time to run.<br />

You can access <strong>and</strong> change the directives using the twin functions ini_get() <strong>and</strong><br />

ini_set(). Listing 24.2 shows a simple script that uses these functions.<br />

Listing 24.2<br />

iniset.php— Resets Variables from the php.ini File<br />

<br />

The ini_set() function takes two parameters.The first is the name of the configuration<br />

directive from php.ini that you would like to change, <strong>and</strong> the second is the value you<br />

would like to change it to. It returns the previous value of the directive.<br />

In this case, you reset the value from the default 30-second (or whatever is set in your<br />

php.ini file) maximum time for a script to run to 120 seconds.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!