I have an index.php file which has to process many different file types. How do I guess the filetype based on the REQUEST_URI? If I request http://site/image.jpg, and all requests redirect through index.php, which looks like this How would I make that work correctly? Should I test based on the extension of the file requested, or is there a way
Tag: php
glob() – sort array of files by last modified datetime stamp
I’m trying to display an array of files in order of date (last modified). I have done this buy looping through the array and sorting it into another array, but is there an easier (more efficient) way …
When and why should $_REQUEST be used instead of $_GET / $_POST / $_COOKIE?
Question in the title. And what happens when all 3 of $_GET[foo], $_POST[foo] and $_COOKIE[foo] exist? Which one of them gets included to $_REQUEST? Answer I’d say never. If I wanted something to be set via the various methods, I’d code for each of them to remind myself that I’d done it that way – otherwise you might end up
How to secure database passwords in PHP?
When a PHP application makes a database connection it of course generally needs to pass a login and password. If I’m using a single, minimum-permission login for my application, then the PHP needs to …
How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?
What is the difference between == and === in PHP? What would be some useful examples? Additionally, how are these operators used in JavaScript? Are they related to PHP?
Does PHP class property scope overridden by passing as reference?
In PHP, if you return a reference to a protected/private property to a class outside the scope of the property does the reference override the scope? e.g. Is this correct and is the array bar being passed by reference? Answer Well, your sample code is not PHP, but yes, if you return a reference to a protected variable, you can
Get PHP to stop replacing ‘.’ characters in $_GET or $_POST arrays?
If I pass PHP variables with . in their names via $_GET PHP auto-replaces them with _ characters. For example: <?php echo "url is ".$_SERVER['REQUEST_URI']."
“; echo “x.y is “.$_GET[‘x.y’]….
How do I use PHP to get the current year?
I want to put a copyright notice in the footer of a web site, but I think it’s incredibly tacky for the year to be outdated. How would I make the year update automatically with PHP 4 or PHP 5? Answer You can use either date or strftime. In this case I’d say it doesn’t matter as a year is a year,
Compile a PHP script in Linux
I know PHP scripts don’t actually compile until they are run. However, say I want to create a small simple program and compile it to a binary without requiring the PHP binary. How could I do this? I’ve seen a few IDE’s out there that would do this, but either they are all for windows or the Linux versions don’t
PHP equivalent of .NET/Java’s toString()
How do I convert the value of a PHP variable to string? I was looking for something better than concatenating with an empty string: Like the ToString() method in Java or .NET. Answer You can use the casting operators: There are more details for string casting and conversion in the Strings section of the PHP manual, including special handling for