php5

performance of loading php classes and the use of 'extends'

Hi, I have an includes.php page that I load at the start of every page of my website. As I develop the website, the number of classes that I am using is growing. So I end up with something like this: $db = new DB($config); $login = new Login($db, $config); $form = new Form($db, $config); And the list goes on and on. I have two questi...

PHP: Populating an array with the names of the next 12 months

for($x=0; $x<12; $x++) { $month = mktime(0, 0, 0, date("m")+$x, date("d"), date("Y")); $key = date('m', $month); $monthname = date('F', $month); $months[$key] = $monthname; } I know for sure I'm doing the math incorrectly for the 4th parameter of mktime. I'm starting with the current month number ( 7 being July ) and a...

Unable to call the built in mb_internal_encoding method !?!

I'm trying to install indefero on a CentOS 5.3 VMware 'box' and I ran into a problem. Quite early in the installation I get an error that I've been able to narrow down to this: [root@code /var/www/html]# cat x.php <?php mb_internal_encoding("UTF-8"); ?> [root@code /var/www/html]# php x.php PHP Fatal error: Call to undefined func...

How can I read/write from/to a file, byte by byte, with PHP5?

I've worked with reading and writing text files with PHP. Now, I'd like to read and write binary files. I've not found any useful resources/tutorials for doing this with PHP5. Is it possible? How? Specifically, I'll be searching for specific 2-byte patterns. If it matters, I'm on a Mac (OS X 10.4 Tiger). ...

How to send more 5000 character to next page

Hi friends, I need to save a content into a file. The content is more than 5000 character. I cant able to send this through url as query string. Its showing Unspecified error. How to achieve this. I am using PHP here. So, i tried to send this content value's through ajax concept to another php file for storing. After a button click i wan...

What should every web developer know about encryption?

I've just landed a PHP5 gig. I won't be handling the parts of the application that involve super sensitive data, but I still know embarrassingly little about security and encryption methods. I only know the very basics (don't store passwords in plaintext, don't allow users to run code using post data, etc). What do I need to know to keep...

Best way to test for databases/connections

Is there a way to unit-test classes wich require database connections? e.g. User-Classes (DB-)Object mocking didn't quite help ...

__construct() { issue for PHP4 and PHP5. maybe an another reason...

Hi friends, I have weird issue with CodeIgniter, here is a start part of my controller class Home extends Controller { /** * Constructor */ public function __construct() { parent::Controller(); } ... everything is working fine at localhost, but when I try same at server, I come cross with an error like b...

Should PHP session be created before login or after successful login

If PHP session is created before login, there will be one session file created for each request to login page. The problem is if user makes multiple requests to server through a script then those many session files will be created. If user wants to attack server,he can send abnormally huge number of requests creating so many session fil...

php 4 to 5 porting question on how to reset a class

Someone wrote the following php4 code which I now am trying to port to php5: the class is Foo (name changed to protect the guilty). In one of the methods, we'll call it save() the class apparently is reset like this: $this = new Foo($this->Foo_Id); That results in the following error: ( ! ) Fatal error: Cannot re-assign $this in ......

[PHP] Inserting an array of lines into an SQL table

Hello everyone, I would really appreciate if you would take a look at this piece of code: <?php if(isset($_POST['add'])) { $self = $_SERVER['PHP_SELF']; //the $self variable equals this file $ipaddress = ("$_SERVER[REMOTE_ADDR]"); //the $ipaddress var equals users IP //connect $connect = mysql_connect($host,$username,$password) or di...

Reference a method of container object in PHP?

Given the following in PHP: <?php class foo { public $bar; function __construct() { "Foo Exists!"; } function magic_bullet($id) { switch($id) { case 1: echo "There is no spoon! "; case 2: echo "Or is there... "; break; } } } class bar { function __construct() { echo "Bar exists"; ...

C# String.Format() Equivalent in PHP?

I'm building a rather large Lucene.NET search expression. Is there a best practices way to do the string replacement in PHP? It doesn't have to be this way, but I'm hoping for something similar to the C# String.Format method. Here's what the logic would look like in C#. var filter = "content:{0} title:{0}^4.0 path.title:{0}^4.0 descri...

how to create phpdoc Tutorial / Extended pages to supplement commented code

I'm trying everything I can to get phpdocumentor to allow me to use the DocBook tutorial format to supplement the documentation it creates: I am using Eclipse I've installed phpDocumentor via PEAR on an OSX machine I can run and auto generate code from my php classes It won't format Tutorials - I can't find a solution I've tried movi...

Wordpress and PHP 5.3

Can anyone offer any suggestions as to why wp-admin/options-general.php won't load on my Wordpress installation in PHP 5.3? If I enable debugging and then have PHP report errors, I do get deprecation errors, but they don't seem relevant. Further, if I fix these errors, the page still does not load. The top bar and several navigation box...

OpenID in PHP 5.3

Does anyone have openid working in a PHP 5.3 installation? None of the libraries I've tried seem to be working. ...

PHP5: Iterating through a list of child nodes (equivalent of child_nodes())?

All, I have an XML document that looks something like this: <root> <profile> <childA> <childB> <childC> <profile> <blah> <blah> <foo> <bar> <root> I'd like to be able to grab the 'profile' node, then iterate through it's children ('childA', 'childB', etc) So far, my code looks like this: $doc ...

Get code line and file that's executing the current function in PHP?

Imagine I have the following situation: File1.php <?php include("Function.php"); log("test"); ?> Function.php <?php function log($msg) { echo ""; } ?> I want to change the log function so that it would produce the following: test (file: File1.php, line number: 3) So, any way to get the file name and the line number of...

Why does this pdo::mysql code crash on windows??

Why does this pdo::mysql code crash on windows??? <?php $username = "root"; $password = ""; try { $dsn = "mysql:host=localhost;dbname=employees"; $dbh = new PDO($dsn, $username, $password); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected to datab...

Selections and localization with Smarty

I'm trying to implements selection lists using Smarty and I'm aware of the {html_options}. The application must support localization (which I implemented as described in this post). Is it possible to combine the two? I'm currently handling it by parsing through the items with {section name=i loop=$list} and "manually" generating the HT...