php

Cakephp - detect if unable to connect to database and recover gracefully

I have a few sites built with Cakephp. If any of these sites lose their connection to the database for whatever reason it does not handle it well. Basically it renders itself inside itself trying to display an error over and over until the browser crashes. The rendering itself inside itself is caused by the use of requestAction from elem...

When we know a class become too much ?

I start to learn class in PHP. According to my experience with other language, i can tell class is different then function. So, how we spot if our class start to be too much and too important and how we minimize its impact ? EDIT : The question is more able how to spot pattern of the writing class problem. Personally. I expect an answer...

PHP how to connect more then one db

how to connect more then one DB in php... but the DB servers are same . but the DB is different. same single page i need to fetch the result from all the 3 db to display. Thank you ...

Redirecting to a new page

Hi, I have defined a function in which i want to open a page on a new window. The function has following code: echo"<script>window.location.href='http://localhost/paymentsystem/views/payment.php?id=".$id."'&lt;/script&gt;" ; Right now its opening the page on the same window. I want to know how can i open this page on a new tab? R...

php - disconnecting and connecting to multiple databases

Hi, I want to be able to switch from the current db to multiple dbs though a loop: $query = mysql_query("SELECT * FROM `linkedin` ORDER BY id", $CON ) or die( mysql_error() ); if( mysql_num_rows( $query ) != 0 ) { $last_update = time() / 60; while( $rows = mysql_fetch_array( $query ) ) { $contacts_db = "NNJN_" . $rows['e...

How to work with session variables in php mvc pattern

Hello, I just found out that I loose any reference to the session array if I create a new view and try to set a session variable in the controller. The array just comes out as empty. I actually try to use the session array to store the post vars from a multistep registration form. This was actually working when the php was spachetticode,...

PHP form validation question?

I have a form that validates the email address and I want to be able to place echo '<p class="error">Please enter a valid email address!</p>'; anywhere on the web page without having to put the validation process within the html? Or should I include the validation process in the HTML form? Here is the php code. if (preg_match ('/^[\w...

How to store $ in a PHP variable?

I want to store a $ character in a PHP variable. $var = "pas$wd"; I get the following error Notice: Undefined variable: wd in C:\xxxxx on line x Help. ...

What's the best way to automatically print an HTML header and bottom in php?

Currently I'm using: PrintHeader(); /* Page code... */ PrintBottom(); Is there a better way? ...

Sample twitter application.

<?php function updateTwitter($status) { // Twitter login information $username = 'xxxxx'; $password = 'xxxxxx'; // The url of the update function $url = 'http://twitter.com/statuses/update.xml'; // Arguments we are posting to Twitter $postargs = 'status='.urlencode($status); // Will store the respo...

What is the best way to set up a PHP development environment on a Mac?

When I do PHP, I use XAMPP to set up a development environment on Windows, then upload to Linux servers, works very well. I'm now passing on a PHP project to a person who has a Mac so he needs a local PHP dev environment. I noticed XAMPP has a version for Mac which I will recommend. But knowing that Mac is always a bit different, has a...

PHP how to remove the html tags(<DIV></DIV>,<P></P>,<SPAN></SPAN>) from the string

Hi frns, Am using the strip_tags() to remove the HTML tags from one content . but i wants to remove the html (<DIV></DIV>,<P></P>,<SPAN></SPAN>) tags apart from the <img> tag and <a> , i don't want to remove the <img ><a> tag from that . but need to remove other all html tags from that content how can i do help me. thanks ...

How to do MEMCACHE in WAMP server WINDOWS XP

Hi Iam running WAMP server and just enabled php_memcache extension and have tried the code <?php $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); $version = $memcache->getVersion(); echo "Server's version: ".$version."<br/>\n"; $tmp_object = new stdClass; $tmp_object->str_attr = 'test'; ...

Generating a salt in PHP

What's the best way to generate a cryptographically secure 32 bytes salt in PHP, without depending on libraries seldom included in typical PHP installations? After some googling I discovered that mt_rand is not considered secure enough, but I haven't found a suggestion for a replacement. One article suggested reading from /dev/random bu...

Is it possible to send an email and auto redirect in single php file?

As the title said: Is it possible to send an email (using php mail()) and after sending the email, auto redirect to another page. All the codes will be in single php file? Code-wise, should be something like this: if(mail(argument...)){ header("Location: www.google.com"); } I think I would get a: "Error: header information alrea...

large XSD validation with PHP - performance problem

Hallo, I have a very long XSD scheme. And the validation process (via PHP) is taking 10 seconds. Do you have some ideas how I can improve performance? The XSD file is not changes often, but I can not change it, it is external. the XML validated is about 500 lines. Any ideas on XSD validation performance? Thanks. ...

Open an excel file using COM and save it as .xml file

Hi. Im trying the following code: <?php $workbook = "D:\b2\\test.XLS"; $sheet = "Sheet1"; #Instantiate the spreadsheet component. $ex = new COM("Excel.sheet") or Die ("Did not connect"); #Get the application name and version print "Application name:{$ex->Application->value}<BR>" ; print "L...

PHP form validation question?

Is it necessary to validate a name or street address? when I have it coded in the following format. And if so why? $address = mysqli_real_escape_string($mysqli, htmlentities($_POST['address'])); $name = mysqli_real_escape_string($mysqli, htmlentities($_POST['name'])); ...

How to replace the characters in fixed positions in PHP?

I want to replace with the 4~8 characters of a string with *,how to do it? HelloWorld => Hell****ld ...

validate a .edu or .ac email address

Hello, I'm a noob but trying vigorously to simply validate email addresses that only end in ".edu" or ".ac" is there a simple function/script/solution to this seemingly simple problem? able to use php,javascript or jquery. Any help would be great thanks in advance! ...