php

Performance of try-catch in php

What kind of performance implications are there to consider when using try-catch statements in php 5? I've read some old and seemingly conflicting information on this subject on the web before. A lot of the framework I currently have to work with was created on php 4 and lacks many of the niceties of php 5. So, I don't have much experi...

Calling PHP functions within HEREDOC strings

In PHP, the HEREDOC string declarations are really useful for outputting a block of html. You can have it parse in variables just by prefixing them with $, but for more complicated syntax (like $var[2][3]), you have to put your expression inside {} braces. In PHP 5, it is possible to actually make function calls within {} braces inside...

How to determine order for new item?

Hi, I have a members table in MySQL CREATE TABLE `members` ( `id` int(10) unsigned NOT NULL auto_increment, `name` varchar(65) collate utf8_unicode_ci NOT NULL, `order` tinyint(3) unsigned NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB; And I would like to let users order the members how they like. I'm storing the...

PHP :: Emulate <form method="post">, forwarding user to page

Hi, I'm working on a PHP application that links into the Protx VSP Direct payment gateway. To handle "3D Secure" requests from the credit card processing company, I need to forward the user to a different website, mimicking a form that has been posted. I'm trying to use the cURL libraries, but seem to have hit a problem. My code is the f...

A script to change all tables and fields to the utf-8-bin collation in MYSQL

Is there a SQL or PHP script that I can run that will change the default collation in all tables and fields in a database? I can write one myself, but I think that this should be something that readily available at a site like this. If I can come up with one myself before somebody posts one, I will post it myself. ...

Validate an incoming SOAP request to the WSDL in PHP

The built-in PHP extension for SOAP doesn't validate everything in the incoming SOAP request against the XML Schema in the WSDL. It does check for the existence of basic entities, but when you have something complicated like simpleType restrictions the extension pretty much ignores their existence. What is the best way to validate the S...

How to get PHPMyAdmin to show MySQL warnings?

I use PHPMyAdmin for convenience in updating a remote database. But it doesn't show warnings, by default, which recently got me into some embarrassing trouble where I was updating a SET field with string not on its list and not noticing the problem. I'm using 2.11.9.1 (Dreamhost's default install). On the PHPMyAdmin wiki it lists "Di...

How do I make WISA act like LAMP (Protecting .mp3s on IIS)

I have created a few small flash widgets that stream .mp3 audio from an Apache/php host. The mp3 file cannot be directly accessed and does not save it self to the browsers cache. To do this I set the mp3 file permission on the host to "owner: read/write" (numeric value 600). This makes it so that only my .php file can read the .mp3. Th...

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? ...

global variables in php not working as expected

I'm having trouble with global variables in php. I have a $screen var set in one file, which requires another file that calls an initSession() defined in yet another file. The initSession() declares "global $screen" and then processes $screen further down using the value set in the very first script. How is this possible? To make thing...

How can I turn on PHP errors display on just a subfolder

I don't want PHP errors to display /html, but I want them to display in /html/beta/usercomponent. Everything is set up so that errors do not display at all. How can I get errors to just show up in that one folder (and its subfolders)? ...

Can I refactor my MySql queries into one query based on number of results?

I have a table y Which has two columns a and b Entries are a b 1 2 1 3 1 4 0 5 0 2 0 4 I want to get 2,3,4 if I search column a for 1, and 5,2,4 if I search column a. So, if I search A for something that is in A, (1) I get those rows, and if there are no entries A for given value, give me the 'Defaults' (a = '0') ...

Is "do not load this page directly" really necessary in PHP?

I was going to ask what the best way to do this is, but then decided I should ask whether or not it is even necessary. I have never seen it done in JSP development, but it appears to be common practice in PHP. What is the reasoning behind this, and if I do not protect against this, what else should I be taking into consideration? ...

Good PHP ORM Library?

Does anyone know of a good object-relational-mapping library for PHP? I know of PDO/ADO, but they seem to only provide abstraction of differences between database vendors not an actual mapping between the domain model and the relational model. I'm looking for a PHP library that functions similarly to the way Hibernate does for Java/.Net....

What is the best way to paginate results in php

I need to display many pages of news in a site. Should i do the pagination in the db query using limit or do it in my php script after getting all the results? ...

PHP: How to check if a directory is writeable?

Does anyone know a good way to check to see if a directory is writeable? The function is_writable doesn't work for folders. ...

PHP GD, imagecreatefromstring( ); how to get the image dimensions?

Normally I used imagecreatefromjpeg and then getimagesize(), but with firefox 3 I need to go round this different. So now im using imagecreatefromstring( ), but how do I retreive the images dimesions now ? ...

PHP replace double backslashes "\\" to a single backslash "\"

Okay so im working on this php image upload system but for some reason internet explorer turns my basepath into the same path, but with double backslashes instead of one; ie: C:\\Documents and Settings\\kasper\\Bureaublad\\24.jpg This needs to become C:\Documents and Settings\kasper\Bureaublad\24.jpg. ...

Caching paginated results, purging on update - how to solve?

I've created a forum, and we're implementing an apc and memcache caching solution to save the database some work. I started implementing the cache layer with keys like "Categories::getAll", and if I had user-specific data, I'd append the keys with stuff like the user ID, so you'd get "User::getFavoriteThreads|1471". When a user added a...

Programmatically determine video file format?

Ok, I get the basics of video format - there are some container formats and then you have core video/audio formats. I would like to write a web based application that determines what video/audio codec a file is using. How best can I programmatically determine a video codec? Would it be best to use a standard library via system calls and...