php

How do I check for valid (not dead) links programatically using PHP?

Given a list of urls, I would like to check that each url: Returns a 200 OK status code Returns a response within X amount of time The end goal is a system that is capable of flagging urls as potentially broken so that an administrator can review them. The script will be written in PHP and will most likely run on a daily basis via c...

What's the standard way to determine the number for a primary key?

I'm planning to make a very simple program using php and mySQL. The main page will take information and make a new row in the database with that information. However, I need a number to put in for the primary key. Unfortunately, I have no idea about the normal way to determine what umber to use. Preferably, if I delete a row, that row's ...

What is the best way to move files from one server to another with PHP?

If I setup a CRON that runs a PHP script that in turn moves a file from one server to another, what would be the best way? Assume I have been given the proper username/password , and the protocol (like SFTP) is only prohibited if the language can't support it. I'm really open to options here -- these are XML files that hold order export ...

Restricting IFRAME access in PHP

I am creating a small web page using PHP that will be accessed as an IFRAME from a couple of sites. I'm wanting to restrict access to this site to work ONLY within the "approved" sites, and not other sites or accessed directly. Does anyone have any suggestions? Is this even possible? The PHP site will be Apache, and the sites iframin...

Coalescing regular expressions in PHP

Suppose I have the following two strings containing regular expressions. How do I coalesce them? More specifically, I want to have the two expressions as alternatives. $a = '# /[a-z] #i'; $b = '/ Moo /x'; $c = preg_magic_coalesce('|', $a, $b); // Desired result should be equivalent to: // '/ \/[a-zA-Z] |Moo/' Of course, doing this as ...

PHP: Error in my_thread_global_end(): 1 threads didn't exit

When running PHP in CLI mode, most of the time (not always), the script will hang at the end of execution for about 5 seconds and then output this: Error in my_thread_global_end(): 1 threads didn't exit It doesn't seem to actually have any effect on the script itself. Some web searches turned up blogs which suggest replacing the p...

How to debug in VI

Using vim 7.1, I recently heard you can debug php in VI. But how? ...

Reasons for MySQL authentication error: “Access denied for user 'xxx'@'yyy'”?

What possible reasons could exist for MySQL giving the error “Access denied for user 'xxx'@'yyy'” when trying to access a database using PHP-mysqli and working fine when using the command-line mysql tool with exactly the same username, password, socket, database and host? Update: There were indeed three users in the mysql.user table, eac...

Symfony app - how to add calculated fields to Propel objects?

What is the best way of working with calculated fields of Propel objects? Say I have an object "Customer" that has a corresponding table "customers" and each column corresponds to an attribute of my object. What I would like to do is: add a calculated attribute "Number of completed orders" to my object when using it on View A but not on...

What's the diference between the different XML parsing libraries in PHP5?

The original question is below, but I changed the title because I think it will be easier to find others with the same doubt. In the end, a XHTML document is a XML document. It's a beginner question, but I would like to know which do you think is the best library for parsing XHTML documents in PHP5? I have generated the XHTML from HTML...

PHP mangles my dates

$doba = explode("/", $dob); $date = date("Y-m-d", mktime(0,0,0, $doba[0], $doba[1], $doba[2])); The above code turns any date i pass through into 1999-11-30 and i know it was working yesterday. Date is correct when I echo $doba. Anyone have any ideas? Cheers ...

PHP: how to save cookies for remote web pages ?

Hiya - I've got a PHP application which needs to grab the contents from another web page, and the web page I'm reading needs a cookie. I've found info on how to make this call once i have the cookie ( http://groups.google.com/group/comp.lang.php/msg/4f618114ab15ae2a ), however I've no idea how to generate the cookie, or how / where the ...

How do I check if ini_set() is enabled either in the global PHP.INI or in my PHP script?

I have an app that is failing on the install. The vendor says I probably have ini_set() disabled. How can I check this? ...

What $_POST[] do i need to post to a forum?

Hi! I am admin on a forum. Earlier we had phpbb 2.0 and i made a bot that could write to the forum. Now, we have upgraded the forum to phpbb 3.0, but i can't get my bot to write to the forum anymore. I have looked for a solution, but now i am out of ideas. So it would have been great if anyone have a suggestion. i have btw used CURL a...

PHP SimpleXML::addChild with empty string - redundant node

Calling addChild with an empty string as the value (or even with whitespace) seems to cause a redundant SimpleXml node to be added inside the node instead of adding just the node with no value. Does anyone know of a workaround for this? ...

php observer pattern to log user out when session times out

I'm trying to log users out when the user's session timeout happens. Logging users out - in my case - requires modifying the user's "online" status in a database. I was thinking that I might be able to use the observer pattern to make something that would monitor the state of the user session and trigger a callback when the session expi...

How are associative arrays implemented in PHP?

Can someone explain how PHP implements associative arrays? What underlying data structure does PHP use? Does PHP hash the key and store it in some kind of hash map? I am curious because I was wondering what the performance of associative arrays where when inserting and searching for keys. ...

How can web form content be preserved for the back button

When a web form is submitted and takes the user to another page, it is quite often the case that the user will click the Back button in order to submit the form again (the form is an advanced search in my case.) How can I reliably preserve the form options selected by the user when they click Back (so they don't have to start from scrat...

How does MediaWiki compose the image paths?

I have a Perl app. that parses MediaWiki SQL tables and displays data from multiple wiki pages. I need to be able to re-create the absolute image path to display the images, eg: [.../f/fc/Herbs.jpg/300px-Herbs.jpg] From MediaWiki Manual:Image_Authorisation: "the [image] path can be calculated easily from the file name and..." How is th...

I'm somewhat confused about the serialization of a PHP associative array.

a:3:{i:0;i:4;i:1;i:3;i:2;i:2;} Am I right to say that this is an array of size 3 where the key value pairs are 0->4, 1->3, and 2->2? If so, I find this representation awfully confusing. At first, I thought it was a listing of values (or the array contained {0, 4, 1, 3, 2, 2}), but I figured that the a:3: was the size of the array. And i...