php

PHP is_readable trouble with open_basedir

I've recently gotten an error when I deployed an application. It used "is_readable" on a path within the include path, but one that was restricted by "open_basedir". This gave me a fatal error. Is there another function that I could use to see if a file is includable, before actually including it? Edit: this works, but how do I detect...

iPhone Feedback Service with PHP

HI All, Has anybody been able to extract the device tokens from the binary data that iPhone APNS feedback service returns using PHP? I am looking for something similar to what is been implementented using python here http://www.google.com/codesearch/p?hl=en&sa=N&cd=2&ct=rc#m5eOMDWiKUs/APNSWrapper/%5F%5Finit%5F%5F.py&q=f...

Simple preg_replace

I cant figure out preg_replace at all, it just looks chinese to me, anyway I just need to remove "&page-X" from a string if its there. X being a number of course, if anyone has a link to a useful preg_replace tutorial for beginners that would also be handy! ...

PHPUnit: Verifying that array has a key with given value

Given the following class: <?php class Example { private $Other; public function __construct ($Other) { $this->Other = $Other; } public function query () { $params = array( 'key1' => 'Value 1' , 'key2' => 'Value 2' ); $this->Other->post($params); ...

Returning an Oracle error in PHP?

Not sure if that makes sense, but say I have this code... $updateSql = oci_parse($conn, 'update "table" SET "column"=:column where "Unique_Record_Id" = :Unique_Record_Id'); OCIBindByName($updateSql, ":Unique_Record_Id", $absenceData['Unique_Record_Id']); OCIBindByName($updateSql, ":column", $column); if(oci_execute($updateSql)){ // np...

How to find the culprit module or script on huge Apache/PHP resident memory usage ?

System: Centos 5.3 x86_64, with Apache 2.2 and PHP 5.2 as module (with mysql and oracle connectors) How to debug memory usage / leaks ? dmalloc ? Valgrind ? auto_prepend_file ? We're looking at 500+ MB VSZ and 50+ MB RSS for example, but it can be somewhat higher. And as the instances add up, we end up needing much more memory than wit...

Automate variable declaration PHP

I want to try and write a function to automate some of the legwork in checking/declaring a variable i.e. function checkVariable($var) { if(!isset($var)||empty($var)) { return ''; } else { return $var; } } $myvar = checkVariable($myvar); obviously, this isn't going to work, because the variable doesn't exist pr...

Make sure most recent SQL query result is used in autosuggest

Hi all, I'm using the PHP code below to get results to return to an autosuggest / autocomplete. The problem is that if an earlier SQL query takes longer to return from the database than the most recent SQL query then the results of the older query will be displayed in the autosuggest results box. So if you start searching for Thomas, it...

regular expression for converting underscores to dash in php

I am trying to convert an underscore to dash in php. hi i have a regular expression that converts white spaces to dash but how can i achieve underscore to dash? $item = preg_replace('/\ +/', '-', $item); ...

row(s) affected in mysql update with PHP

How do i find if my update is successful or not? i update using a where uniqueName=name so i should always only update 0 rows or 1. What is a good way to check if i updated a row or not? ...

"Signed" email in PHP

How would one "sign" an outgoing email using PHP? The proper header I am looking at is: signed-by mydomain.com ...

PHP page source copy

I need to write a script that goes to a page, copies the source of the page, and stores it as a string to be outputted withing another page. I'm forced to do this due to the fact that the target page is dynamic, and apparently we need static records of that page within our internal system. I know a limited amount of php. Can anyone poi...

Encode in ASP and decode in PHP

Hello, I am looking for 2 lines of code, one which will encrypt (using a shared key) a string in ASP and the other will decode the same string in PHP. Can someone please suggest. ...

PHP and Mcrypt for alphabet only crypts?

Below is my current encryption function. define('ENCRYPT_KEY', 'ldkKKmeJddeFffKdjeddd'); function market_dock_api_encrypt($string) { $key = ENCRYPT_KEY; //preset key to use on all encrypt and decrypts. $result = ''; for($i=0; $i<strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($ke...

Generating CSV file and then forcing the file to download.

I have an issue, my application works as follows. First echo to the user that the generating of the csv file has started. eg. echo 'Building of csv file started'; then I build the csv file. Now I want to force the file to download, and this works perfectly. this is my code header('Content-Type: application/csv'); header('Co...

Conditionally defining functions

Is there any advantage to conditionally defining functions in PHP? For example, if I have a script similar to this function abc() { ... } function xyz() { ... } if (user_is_logged_in()) { ... abc(); ... xyz(); } else echo 'Not logged in.'; Would there be any advantage, and would it be legal, to mo...

What does a HTTP Request that references a file in the middle of the path?

I'm writting a HTTP server and when i tried the Serendipity PHP Blog i get requests from the browser like this one: GET /serendipity_admin.php/templates/default/admin/pluginmanager.css HTTP/1.1 The "/serendipity_admin.php" file does exist so the "/serendipity_admin.php/templates/default/admin/pluginmanager.css" obviously must fail. W...

What is the largest volume CakePHP site out there?

What is the largest website out there using the CakePHP framework? I'm interested in pageview volume mostly, so I will use Alexa Traffic Rank and Reach metrics to evaluate the answers. ...

PHP MySQLi Multiple Inserts

I'm wondering if prepared statements work the same as a normal mysql_query with multiple VALUES. INSERT INTO table (a,b) VALUES ('a','b'), ('c','d'); VS $sql = $db->prepare('INSERT INTO table (a,b) VALUES (?, ?); If I use the prepared statement in a loop, is MySQL optimizing the insert in the background to work like it would in the...

PHP; use sessions or re-use query?

Hey, I'm interested in what is the more efficient way of handling user data in my game. When someone is playing the game, data from the server will constantly need to be queried from the database. So I want to know if it is more efficient to keep querying the database or to store the data from the first query in a session and then keep...