php

How should I make up for the lack of static initializers in PHP?

I'm thinking about putting every class into a separate file and doing the static initialization outside of the class definition. The problem with this is the fact that the initialization will happen before the said class is actually needed (it will happen when the file which contains the class is included for the first time). It's a pro...

Best Practices: Tracking Banner Impressions

I am writing a banner ad engine in php/mysql. I don't want to use OpenX or a turn-key solution because there is going to be a bunch of custom functionality that I would rather not rely upon an existing system to have to flex to accommodate. Here is the thinking and my current approaches to the impressions architecture: Requests to ban...

Getting the min and max values from a PHP array

Is there a built in PHP function that will allow you get the minimum and maximum values from a PHP array? If not, what's the most efficient way of doing this for the general case? ...

How do you deal with temporary picture uploads in PHP?

I'm creating an online game in PHP where users can create playable characters. Each character can have a user-uploaded portrait. A player can simultaneously have multiple characters, and the pictures for them can be changed anytime. Naturally, the pictures have to be resized and re-compressed to avoid huge files. Here's my problem: When...

Why would MySQL leave out the first row when retrieving from a database?

For some reason I'm having a problem retrieving data from my database. It leaves off the first item being listed. Connection: mysql_select_db($database_my_db, $my_db); $query_rs_jobboards11 = "SELECT * FROM jobBoardsSpecTypes ORDER BY type"; $rs_jobboards11 = mysql_query($query_rs_jobboards11, $my_db) or die(mysql_error());...

How to protect HTML navigation

Hi! I am writing software for an elearning platform. Validation is performed via PHP and MySQL. All content is uploaded into a folder protected for all direct access by HTACCESS and content is only served to users via a PHP routine that validates student credentials and then Fopens the file and sends it to the browser. This is ok for a...

How to get specific content with PHP and DOM Document?

Howdy, I have a url I want to grab. I only want a short piece of content from it. The content in question is in a div that has a ID of sample. <div id="sample"> Content </div> I can grab the file like so: $url= file_get_contents('http://www.example.com/'); But how do I select just that sample div. Any ideas? ...

cURL, frames & letitbit.net: Could you help me please?

I have written a script for Letitbit.net. With help of cURL I can get to the page where after 60 secs is to appear the link to the file I want to download. That page uses frames... If I get to the page via a browser, the sourse code looks just like this: <frameset rows="125,70,*" frameborder="no" border="0" framespacing="0"> <frame src=...

PHP: Is this syntax okay for calling a function with arguments?

I'm wondering if there are any syntactic problems calling a function that only has one argument with multiple arguments. For example: function foobar( $biff ) { // do stuff... } ... and then call the function: echo foobar( 'Hello', 'world', '!!!' ) I believe that $biff === 'Hello', right? And then I will use array_slice( func_get...

Strange behavior in PHP mail function, address does not exist.

I recently had this issue with a client. The code read: ini_set( "sendmail_from", "noreply@<current-domain>.com" ); // $target_email has been validated as a value username. // $subject is a simple String. // $message is an HTML message. mail( $target_email, $subject, $message ); When I tested this on my machine, it worked fine. Whe...

php automating login and form submission Tutorial(s)

Looking into doing some PHP script automation, Need something that will login to a system, enter some values, submit a form and return a success/failed message. Don't know if this is a factor but the website is heavy on AJAX as well. Looking for help in where to get started, maybe some tutorials, code examples, Am I looking at the probl...

Is it possible to convert between Unicode normal forms in PHP?

For example, in one Unicode normal form á is always represented as an unaccented letter a and a combining accent mark, in another it must be a single pre-combined Unicode character. How would I convert between these forms in PHP? ...

PHP4 - "Fatal error: Cannot redeclare function()"

Second time I've ran into this... I have function foo() that has a helper function inside called formatStr() which is used in an array_map() call. When I call foo() more than once within a script I get a "Fatal error: Cannot redelcare formatStr()". Which leads me to believe formatStr() is not declared locally in the function but globa...

Bash / PHP quoting command line argument

I have a PHP program that uses a Bash script to convert a pdf. However if the filename contains spaces it is not passed through the bash script correctly. How do you escape filenames with spaces within a bash script? Do you have to do something special to quote the filename for the "OUTFILE" variable? Bash script: #!/bin/bash INFI...

(My)SQL - batch update

Hey, I have a table with "id", "name", and "weight" columns. Weight is an unsigned small int. I have a page that displays items ordered by "weight ASC". It'll use drag-n-drop, and once the order is changed, will pass out a comma-separated string of ids (in the new order). Let's say there's 10 items in that table. Here's what I have so ...

How to save a snapshot of a SWF to the server with AS3?

I am facing the task of having to upload a snapshot to the server. But I don't want the user to download the image to their computer. I have explored a few solutions of generating an image serverside with PHP, but they all seem to use a method where the server sends the image to the user. See for instance: http://mattkenefick.com/blo...

How to change PHP form redirection depending on radio button or drop-down list selected?

Hi! The idea is to be able to perform some search query depending on radio button selected or drop-down choice. I know my PHP code is wrong, that's why I need your help ;-) My testing page is available here (click). HTML code is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-stri...

How to include files with HTTPS - PHP

I made a form process and broke the code up into different files to stay clean and organized. Now I am setting up the form for https security. Do all the files I pull into my page have to be called as https as well? In which case I can no longer use include(); as it no longer allows relative paths? Is the solution to use file_get_cont...

What are the best free CASE tools for PHP?

What are your favorite free CASE/UML/Code generation/diagramming tools that you use with PHP? There are various commercial products that support code generation in PHP language, are there any free CASE tools? What would you recommend? ...

Blocking vulgar terms from an Email Invite

Hello, The code below contains some PHP code that allows users to send out email invites to others. It works fine. However, I'm trying to add a function called "check_porn_terms" so that no user could enter their name as "porn" or other vulgar terms and then send an email under that name recommending my site. The variable "$_POST['se...