Skip to content

Tag: php

Why use sprintf function in PHP?

I am trying to learn more about the PHP function sprintf() but php.net did not help me much as I am still confused, why would you want to use it? Take a look at my example below. Why use this: When this does the same and is easier to write IMO: Am I missing something here? Answer sprintf has all

How to create an error 404 page using PHP?

My file .htaccess handles all requests from /word_here to my internal endpoint /page.php?name=word_here. The PHP script then checks if the requested page is in its array of pages. If not, how can I simulate an error 404? I tried this, but it didn’t result in my 404 page configured via ErrorDocument in t…

How do I throttle my site’s API users?

The legitimate users of my site occasionally hammer the server with API requests that cause undesirable results. I want to institute a limit of no more than say one API call every 5 seconds or n calls per minute (haven’t figured out the exact limit yet). I could obviously log every API call in a DB and …

What is PHPSESSID?

I’m playing around with cookies. And I dont have any cookies called PHPSESSID. Do i need it? Can i remove it? Whats the “function” of it? Prints: Answer PHP uses one of two methods to keep track of sessions. If cookies are enabled, like in your case, it uses them. If cookies are disabled, it…

Is there a way to get all of a DOMElement’s attributes?

I’m reading some XML with PHP and currently using the DOMDocument class to do so. I need a way to grab the names and values of a tag’s (instance of DOMElement) attributes, without knowing beforehand what any of them are. The documentation doesn’t seem to offer anything like this. I know that…

DBM or SQLite in PHP 5.x

We have a client whose site is hosted on a server (I don’t want to disclose hosting company name) which does not provide DB functionality. We have developed a very simple CMS based site but out implementation uses MySQL. I read somewhere that there are DB like functionality built-in in PHP. I have never…