php

How to safely link to data processing pages in PHP

Let me explain the title: Take the "flag as inappropriate" link on any youtube video as an example. That's basically a link to a page that processes the request (such as, is the person who clicked it a logged-in user, what's the id of the video flagged, etc). If everything goes well, the video is flagged and a right output is given to th...

Is this smart or no?

Is it ok to use this code to trim and escape all post´s in my register function? or is it better practice to trim and escape each and every inputs // Trim and sanitize our input $_POST = array_map('trim', $_POST); $_POST = array_map('mysql_real_escape_string', $_POST); if (invalidinput) dostuff else insert into user (username,passwd) v...

Removing a function at runtime in PHP

I know this question seems hacky and weird, but is there a way to remove a function at runtime in PHP? I have a recursive function declared in a "if" block and want that function to be "valid" only in that "if" block. I don't want this function to be callled outside this block. I found out runkit_function_remove but runkit isn't enable...

PHP SimpleXML with XPath

I have an XML structure that looks like this: <?xml version="1.0"?> <survey> <responses>0</responses> <question> <title>Some survey question</title> <answer> <title>Answer 1</title> <responses>0</responses> </answer> <answer> <title>Answer 2</title> <responses>0</responses> </answer> ....

Directory to array with PHP

Whats the most efficient way of turning the filenames in a directory into an array of strings? Thanks. ...

Fogbugz XML_API PHP CURL File upload

I have built a php script which receives values in $_POST and $_FILES I'm catching those values, and then trying to use CURL to make posts to FogBugz. I can get text fields to work, but not files. $request_url = "http://fogbugz.icarusstudios.com/fogbugz/api.php"; $newTicket = array(); $newTicket['cmd'] = '...

How would I programmatically crop an image to a non-rectangular shape?

I want to crop a rectangular image to a non-rectangular shape. I realize that if you take that completely literally, it's not possible. What I want to end up with is image X, cropped to shape Y, on a transparent background. Let's say for example that I want to take a picture of the Idaho flag and crop it to the shape of the state of Ida...

Can I set a PHP class property from an existing variable?

I am trying to figure out how I want to handle settings in my PHP app. I have pretty much decide that I would like to use a Confg class file so it will be autoloaded and flexible in the future. Below is some stuff I was playing with. I know you cannot set a variable to popluate a Constant so I then try to use a public static propert...

PHP + MySQL + Ajax Search or Data Framework

i tried several ajax/js "frameworks" and "data grids" to show some mysql data, but the problem is that i have to many columns (like 50) and some of then need to be links, images and also get the ID from the same query to create those links the main features that im looking is good search, sort and filter i dont have the time to make al...

PHP parse_ini_file() performance?

I know some people store settings in an .ini file and get the values with parse_ini_file() in PHP. Without running tests, I am curious about performance. Do you know if opcode cache can cache any of this type of stuff if setting are in an ini file? ...

Web CMS Performance: pages/second (Joomla, Drupal, Plone, WP)

Note: I am not into web programming, so forgive my ignorance in case the question is trivial. Also, please don't comment about "how flawed" the out-of-box comparison of these products is. The question is not about how they compete against each other, rather about the reason behind the incredible slowness of ALL of them. Just read about ...

How to get number of rows without SELECTING all rows?

How can i get the number of rows like mysql_num_rows but without having a mysql resource to work from, because i don't know the future scale of my webapp and it could take an hour just to get the number of rows ;) thanks! ...

Turn directory into Zip with PHP

How would I turn a directory into a zip file with PHP? Thanks. ...

Send Facebook Message from Personal website - possible?

I have been comissioned to make a website complete with a user login system with multiple user groups. The users of this site will most likely also be administrators of facebook groups as well. Does anyone know if it is possible to associate facebook credentials with the login, and be able to send out group wide messages from this sepa...

Is threadcaching faster than memcaching?

I recently plugged memcaching into my PHP web software. I have a class, Cache, that manages storing things in my memcache pool. In that class, I also maintain an member array--a "threadcache"--that stores up to 100 of the most-used items. My question is, is threadcaching going to be faster than memcaching? I would think so, coming from ...

Regex & PHP - isolate src attribute from img tag

With PHP, how can I isolate the contents of the src attribute from $foo? The end result I'm looking for would give me just "http://example.com/img/image.jpg" $foo = '<img class="foo bar test" title="test image" src="http://example.com/img/image.jpg" alt="test image" width="100" height="100" />'; ...

PHP/Krumo: accessing arrays within arrays?

I'm using krumo to output data from a page, all the data is accessible through the $page variable. I have a field called customer with the following structure: customer (Array, 1 element) 0 (Array, 1 element) id (String, 2 characters ) 85 How do i actually access id? I've tried $page->customer->id but it doesn't work. On...

What is the best way to learn php?

Hi I'm new to php and I want to learn it because i want to build web applications. For ex: Facebook apps, mobile apps, my own ideas ..etc. What would be the best efficient way to learn PHP or which direction should i take? There are so many books, tutorial and articles out there that teaches you how to learn php and everyone thinks thei...

Show warning/error to user without using wp_die

Hi, I'm currently developing a Wordpress plugin. For my plugin to work I need some info te be filled in on the settings page. Is there a way to warn/throw an error so the blog admin can see this message on his/her dashbord? Is there another function to show errors other than wp_die()? Just in case my plugin (or someone else) screws ...

How to select multiple fields in the same row? (MySQL)

I asked a question yesterday about using MySQL to tally results to a survey. Now my question is, if I had a table of survey questions, a table of survey choices, and a table of users answers to those survey questions, how would I select the survey question along with all the choices for that survey within the same query? Questions Tabl...