php

CakePHP Session vaiable use in view page?

hi i have a varible contaning "username" and want to get these values via session to any of the view page. How can i use session vaible in view ...

Fastest way to iterate array in PHP

I'm studying for the Zend PHP certification. Not sure the answer to this question. Question: What is the best way to iterate and modify every element of an array using PHP 5? a) You cannot modify an array during iteration b) for($i = 0; $i < count($array); $i++) { /* ... */ } c) foreach($array as $key => &$val) { /* ...

Is this PHP login function safe?

I am currently re-writing my functions script (PHP) for my login system. Is the below code safe and a "good" way to check if the user is logged in? function loggedin() { $ID = ($_SESSION['ID']); $sql = "SELECT `online` FROM `users` WHERE `ID` = '$ID'"; $result=mysql_query($sql); $count=mysql_num_r...

how to pass information from php to javascript

I'm working on a web UI control called Folder - it basically mimics Windows Explorer folder - you see a grid of items inside a rectangle and can drag an item around, drop an item inside a different instance of the control, add new items and so on. each item is made of an item template - basically some php code that dictates the look of t...

Create unique alpha numeric string for an input string/url?

I want to create a less than or equal to 10 character unique string for an input string which could be a url http://stackoverflow.com/questions/ask OR an alpha numeric string programming124 but the result should be unique for every input...Is their any function or class that you use for your projects in php... Thanks... ...

Php session files have different owners

i have a problem with my session files... if i go to my site directly (www.example.com) then php session files owner is www-data:www-data but if i go do the site via www.example.com/index.php then the owner of the session files is ftp:www-data and the resulting problem is when i want to start the session but the session file allready ex...

PHP extending class properties

Hi, I have two classes in a PHP application, B extending A for example. Class A has a function which returns some of its other properties in the form of an array of SQL insert queries eg Class A { $property_a; $property_b; $property_c; $property_d; function queries() { $queries = array(); $queries[] = "INSERT INTO xxx VALUES " . $this-...

organizing a list of pages in the wordpress sidebar using last.fm api

so i have my website, which i did in wordpress - http://chrisgruggen.com/class/mpm35/interactive-self-portrait/ my goal is to make the left sidebar have a list of my top bands (19 or 20 will do). i want them to be organized in order of how many play counts they have (using last.fm api) with the highest being at the top. i also want each...

jQuery ajax call to url containing accent character sends bad Uri from IE to server

I was having trouble sending up a url containing accent characters using IE. Here's a simple function: function runjQueryTest(){ var url = "/test/Beyoncé/"; $.get( url, function(){}); } On the server (PHP) I record the value of the request uri ($_SERVER["REQUEST_URI"]) and I see a difference between what FF/Chrome send up ver...

Algorithm for Finding Good, Reliable Players

I've the following players, each value corresponds to a result in percentage of right answers in a given game. $players = array ( 'A' => array(0, 0, 0, 0), 'B' => array(50, 50, 0, 0), 'C' => array(50, 50, 50, 50), 'D' => array(75, 90, 100, 25), 'E' => array(50, 50, 50, 50), 'F' => array(100, 100, 0, 0), 'G' =...

Change Website Character encoding from iso-8859-1 to UTF-8

About 2 years ago I made the mistake of starting a large website using iso-8859-1. I now am having issues with some characters, especially when sending data to the server using ajax. Because of this, I would like to switch to using UTF-8. What issues do you see coming from this? I know I would have to search the site to look for ch...

How to skip using __autoload?

Hi, I have a php file which has multiple classes in it. I noticed that __autoload is being called when I instantiate any of the classes, even after the 'package' file has been autoloaded. This is worrying me, because surely if the initial 'package' .php file has been loaded, it is unnecessary overhead for __autoload when the classes hav...

preg_match_all print *all* matches

Hy guys! I need to print all matches using preg_match_all. $search = preg_match_all($pattern, $string, $matches); foreach ($matches as $match) { echo $match[0]; echo $match[1]; echo $match[...]; } The problem is I don't know how many matches there in my string, and even if I knew and if it was 1000 that would be pretty d...

PHP: Force file download and IE, yet again

Folks, I know there have been lots of threads about forcing the download dialog to pop up, but none of the solutions worked for me yet. My app sends mail to the user's email account, notifying them that "another user sent them a message". Those messages might have links to Excel files. When the user clicks on a link in their GMail/Yaho...

How to sort an array of associative arrays by value of a given key in PHP

Tough to explain so here's an example: $inventory = array( array("type"=>"fruit", "price"=>3.50), array("type"=>"milk", "price"=>2.90), array("type"=>"pork", "price"=>5.43), ); I would like to sort inventory's element by price so I would like: $inventory = array( array("type"=>"pork", "price"=>5.43), array("type"=>"...

Php DOMDocument getting attibute of tag

Hello I have an api response in xml format with a series of items such as this: <item> <title>blah balh</title> <pubDate>Tue, 20 Oct 2009 </pubDate> <media:file date="today" data="example text string"/> </item> I want to use DOMDocument to get the attribute "data" from the tag "media:file". My attempt below doesn't work: $xmldoc = n...

mod_rewrite passing variables

I have the following mod_rewrite rule: RewriteRule ^([^/.]+)/?$ search.php?action=procedure&procedureName=$1 This works fine in redirecting things like /blabla to /search.php?action=procedure&procedureName=blabla The problem is that sometimes I want to pass a 'start' value (for pagination). For example, /blabla/?start=20. Currently,...

Architecture of a PHP app on Amazon EC2

I recently experienced a flood of traffic on a Facebook app I created (mostly for the sake of education, not with any intention of marketing) Needless to say, I did not think about scalability when I created the app. I'm now in a position where my meager virtual server hosted by MediaTemple isn't cutting it at all, and it's really comin...

Returning Wordpress Custom Field Values

I'm trying to echo the key of a custom field (value, such as a URL set while editing a post) back into the document. Here's the overall code: <div id="feature" class="clearfix"> <?php $feature_post = get_posts('category=3&numberposts=1'); foreach( $feature_post as $post ) : ?> <div clas...

debugging tools

I am using Netbeans and programming with PHP. I have seen debugging tools like watches and call stacks. What exactly are watches and call stacks? How do I use them in Netbeans? ...