php

OOPHP suitable alternative to singleton pattern?

Hi, I'm currently working on an oophp application. I have a site class which will contain all of the configuration settings for the app. Originally, I was going to use the singleton pattern to allow each object to reference a single instance of the site object, however mainly due to testing issues involved in this pattern, I've decided t...

Remembering URL until authentication is complete

How do I remember a url in php to serve it to a user after authentication. The idea is the user will request the url but while unauthenticated. In this case, I forward him to the login page, but what's the best practice to save that url so I can serve it to him once authenticated. I thought about saving it in session variables, but not s...

Should I put images on a subdomain to speed up website loading?

I read somewhere that browsers can only send a few concurrent request to resources on a domain. So if we split the resources across subdomains or may be domains .. will it speed up things? Did you experiment something like this? What were the results or issues if any? ...

Check for internet explorer. PHP vs. ie conditional comments?

So I've decided to break up my CSS into an ie6-and-ie7-only file. I will have CSS rules in this file which target ie6 and ie7 only, such as: div { *color: red; /* target ie7 and below */ _color: green; /* target ie6 and below */ } If possible, I prefer to use PHP with $_SERVER['HTTP_USER_AGENT'] to detect the browser, rather t...

PHP warning help?

I keep getting the following error listed below and I was wondering how do I correct this error. Warning: mysqli_close() expects exactly 1 parameter, 0 given in Here is the code listed below. <?php require_once ('./mysqli_connect.php'); // Connect to the db. function make_list ($parent) { global $tasks; echo '<ol>'; foreach ($...

Directing non extension files to .php

I have a file with .php extention www.example.com/thefile.php?name=123 that I want to direct the user to if the user visits any of the following aliases: www.example.com/alias?name=123 www.example.com/unreal?name=123 www.example.com/fake?name=123 Is there a way I can get this done without using a framework that already uses this stru...

PHP: Class segmentation ?

I'm building an Authentification library that's going to have around 45+ methods for dealing with user related stuff. However I've been wondering if it's actually recommendable to keep everything on a single file. Is there a benefit on splitting my class into several subclasses and load them when needed? I can always for example split ...

php how to trim each line in a heredoc (long string)

I'm looking to create a php function that can trim each line in a long string. eg: <?php $txt = <<< HD This is text. This is text. This is text. HD; echo trimHereDoc($txt); output: This is text. This is text. This is text. Yes, I know about the trim() function. Just not sure how to use it on a long strings such a...

Dynamic Table Generation

First let me describe my situation so that you might be able to help me better. There are two parts. 1: I have a program that runs and analyzes a bunch of files. It generates a "report" that will later be fed into a website for DB storage and viewing. This report can contain pretty much any type of data, as the users can query pretty...

How to convert a PHP function to a non-function?

How can I convert the php function in the code below to a non-function. <?php require_once ('./mysqli_connect.php'); // Connect to the db. function make_list ($parent) { global $tasks; echo '<ol>'; foreach ($parent as $task_id => $todo) { echo "<li>$todo"; if (isset($tasks[$task_id])) { ...

What is a good message broker that works with PHP?

I am looking for a message broker (like Apache ActiveMQ for Java) that works with PHP, preferably open-source. Any ideas? ...

Help with classes in php

class Controller { protected $_controller; protected $_action; protected $_template; public $doNotRenderHeader; public $render; function __construct($controller, $action) { $this->_controller = ucfirst($controller); $this->_action = $action; $model = ucfirst($controller);/* Conecting th...

Use of => in PHP

What does this mean in PHP and when is the time to use it? => Another example. foreach ($parent as $task_id => $todo) ...

Using PHP cURL with an HTTP Debugging Proxy

I'm using the app "Fiddler" to debug a GET attempt to a website via PHP cURL. In order to see the cURL traffic I had to specify that the cURL connection use the Fiddler proxy (see code below). $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888'); curl_setopt($ch, CURLOPT_...

get user's country code

hi all I want to use on my site a script that shows the user's country code. I know about maxmind.com's GeoIP PHP API, but I can't install the mod_geoip (not my own server) :( ...

input boxes in table header not working

I have a problem with a table header containing input boxes. I have similar div's in the rest of the table and they work fine. the div is hidden by default, and is absolutely positioned The table inside the div usually just contains a few columns with a single form element in each column. This would be typical: <a>show editrow</a> <...

PHP Bold some words in a string and remove some unbold words

Hi, I am creating an Image Search Engine. Currently, my script does bold the matching words on the keyword. But, some keywords are too long just like the followings. When I search for shah rukh khan, there is an image with the following keyword. 25216d1235653089 shahrukh khan s wallpaper shah rukh actor As you see, the above k...

Controller must have access to model and view. Model must have access to controller and view. View must have access to controller and model. Look what happens!

<? class Launcher { function launch() { new Controller(); } } class Controller { function __construct () { if(!is_object($this->Model)) $this->Model = new Model(); if(!is_object($this->View)) $this->View = new View(); } } class Model { function __construct () { if(!is_object($this->Controlle...

PHP or Java for e-commerce

In developing a web application that will handle credit cards, purchases, digital downloads, is there any real world benefit to using Java over PHP? This will be a store that sells digital downloads. ...

Converting Python code to PHP

What is the following Python code in PHP? import sys li = range(1,777); def countFigure(li, n): m = str(n); return str(li).count(m); # counting figures for substr in range(1,10): print substr, " ", countFigure(li, substr); Wanted output for 777 1 258 2 258 3 258 4 258 5 258 6 258 7 231 8 147...