Skip to content

PHP file_exists and wildcard

Is there a way to write the PHP file_exists function so that it searches a directory for a file with an arbitrary extension. For instance, suppose I knew that a file were called “hello”, but I didn’t know the extension, how would I write a function that searched for a file called hello.* and…

What is mod_php?

While going through a Zend tutorial, I came across the following statement: Note that the php_flag settings in .htaccess only work if you are using mod_php. Can someone explain what that means? Answer mod_php means PHP, as an Apache module. Basically, when loading mod_php as an Apache module, it allows Apache…

How to sort files by date in PHP

I currently have a script which allows me to output the list of files inside the same directory. The output shows the names, and then I used filemtime() function to show the date when the file was modified. How will I sort the output to show the latest modified file? This is what I have for now: Answer You ne…

How can I encrypt a cookie value?

How can I encrypt, and later decrypt, a cookie value in PHP? How secure will the encryption be? Answer I can not simply think of a situation where encrypting data in the cookie is useful. If you want to retain secret data about the user or his preferences, information, whatever, then store it on the server in…