Skip to content
Advertisement

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 the .htaccess showing up. Am I right in

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 do the calculation

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 uses the URL. Although this

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 I can get an attribute’s value if I

How do I set the selected item in a drop down box

Is there any way to set the selected item in a drop down box using the following ‘type’ code?