php

PHP/CGI: Portable and safe way to get PATH_INFO

I'm seeking a portable way to receive the (handy) $_SERVER['PATH_INFO'] variable. After reading a while, it turns out PATH_INFO is originated from CGI/1.1, and my not always be present in all configuration. What is the best (mostly security-wise) way to get that variable - apart from extracting it manually (security concern). ...

Sudden "MySQL server has gone away" error in PHP site

Today one of my websites started showing Error Number: 2006 MySQL server has gone away It's a low-traffic client site running under Apache 2.2.9 (Debian), PHP 5.2.6-1+lenny3 (using CodeIgniter 1.7.1 framework) and MySQL 5.0.51a. I obviously reasearched about the error but all the possible solutions imply that there are big queries goin...

Loading an object from PHP session, does it call constructor?

If I save some object in a php session variable $_SESSION['geoip'] = new GeoIP(); and then on future page loads I use $geoip = $_SESSION['geoip'], will it call the constructor? My constructor for that GeoIP class is making a call to an remote API (CURL), so I was hoping to save on API calls by only doing it the first time and then stori...

How to make child-navigation not affect parent browser history ?

I have a main page which contains a simple iframe. Iframe source = a php file. The PHP have a link the user can click, but whenever clicked, the browser history increases. I want the iframe to be independent, without affecting history. Possible? I am not familiar with ajax btw. PS: Its only 1 link in the iframe which can be clicked. T...

How to convert a multi-level array to ul?

I have the following array. Array ( [24] => Array ( [id] => 24 [name] => Main menu [shortdesc] => mainmenu [status] => active [parentid] => 0 [order] => 0 [children] => Array ( [65] => Array ...

Parse PHP code on the fly and store it in a temp var

Hello all, I'm creating my own templatesystem because I only need a few little operations to be supported. One of them is loading widgets with dynamic data generated from a database in my template. Is there a way to parse PHP code, don't display the result but store it in a variable and then use the generated source from that variable...

Zend DB Select with multiple table joins

Hey all, Trying to replicate the following query using Zend_Db_Select. Any pointers? SELECT compounds.id as compounds_id, reactions.id as reactions_id, reaction_compound.number as reaction_compound_number FROM compounds, reactions, reaction_compound WHERE compounds.id IN (68,74,112) AND compounds.id = reaction_compoun...

PHPunit command line variable on windows giving trouble

I installed PHPunit via the commandline and added it to my path variables.I then tried to see if it will run, but I got a weird error. Must be something in some file that I didn't configure correctly, but there are over 800 lines in all the PHPUnit folder that reference to that folder, so I'm at a loss as to which one it is. Most will ...

If not following correct procedure?

Hi, I'm working on a Content Management System, and so far so good. I'm trying to get the system to work with a maintenance mode system. This is the code in the script to display the maintenance stuff: if ($maintenance['value'] == "1") {?> <div id="content"> <div id="errmsg"> <?php echo $maintenance['notes']; ?> </d...

Paypal return URL

I'm programming a PHP site with Paypal integration and I've stumbled into a problem with the return url. I need users to be returned back to a specific url on my site after in the final step. I have things in my session variables that need to be moved into a database. The problem is, the Paypal secure form that has the "return" button ...

PHP header("Refresh") problems

I have some code like: header('Refresh: 15; url=' . $url); This works fine, except when people are visiting this url via Twitter (posted from a Hootesuite client). Apparently, in all browsers other than IE this works properly. With IE, from the Hootesuite link, this does not refresh properly; a direct link does. Why? ...

PHP Simple HTML DOM Parser problem with split()

I want to use the PHP Simple HTML DOM Parser to display all my Left4Dead Steam achievements on my website. The achievements list on the steam community website looks something like this: <img src="…" /><br /> <div class="achieveImgHolder"><img src="…" /></div> <div class="achieveTxtHolder"> <img src="…" /> <div class="achieveTxt"> <...

PHP strtotime returning wrong results

strtotime('3rd January,2010') returns 1230993600 in GMT+5:30. While according to this, unix timestamp 1230993600 is 3rd January,2009. So it's off by one year. It's happening on PHP 5.2.6 as well as 5.2.11 . ...

Ruby REXML throws ParseException, but PHP xml parser works

I'm trying to call a web service from a PHP page via a Ruby script. The PHP script returns a string and itself calls another web service; I've tested the PHP script alone and it returns a single string. I'm trying to call this method via RPC using the following code: require 'soap/rpc/driver' driver = SOAP::RPC:Driver.new('http://mysi...

Converting HTML to plain text in PHP for e-mail

I use TinyMCE to allow minimal formatting of text within my site. From the HTML that's produced, I'd like to convert it to plain text for e-mail. I've been using a class called html2text, but it's really lacking in UTF-8 support, among other things. I do, however, like that it maps certain HTML tags to plain text formatting — like puttin...

PHP PDO Caching

Hi there, I've been looking for an answer to this but haven't found it anywhere. Are calls to PDO::prepare() cached, or should I cache the result myself, i.e. if I do the following function foo () { $handle = PDO::prepare(...); /* do stuff with the handle */ } will the prepare() statement be cached by PDO so that it's quickly re...

Creating 2-D matrix in php

The thing is I have to create a 2D matrix in php where each row and column must have a key. I tried to do this but what happens is that a 2-D array is created which does not resemble a matrix. I used the following code: $x=$row['start_id']; $y=$row['dest_id']; $d=$row['distance']; $this->map[$x][$y]=$d; Here map is the intended matri...

PHP: Is it possible to retrieve the class name of a child class?

class Bob extends Person { //do some stuff } class Person { public function __construct() { //get the class name of the class that is extending this one //should be Bob } } How can I get the class name of Bob from inside the constructor of the Person class? ...

Need Help with Magento Mini-Search

I have the below code courtesy to Edmond's Ecommerce that converts Magento's standard mini-search form to a more detailed mini-search like the ones seen in Amazon and eBay. At this juncture, I'm able to get to the sub-categories of the root directory, but instead, I would like to pull out the array from the sub-sub-categories. Root Direc...

CakePHP Authentication with Prefix Routing

I'm building a site with CakePHP which I would like to have 3 sections: public area user area admin area I've setup prefix routing in routes.php which looks like Router::connect('/user/:controller/:action/*', array('prefix' => 'user', 'user' => true)); Router::connect('/admin/:controller/:action/*', array('prefix' => 'admin', 'admin...