1 / 3
Caption Text
2 / 3
Caption Two
3 / 3
Caption Three margin testing

Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Friday, August 13, 2010

Install PHP cURL on Ubuntu 10.04

http://www.blog.highub.com/php/php-core/linux-ubuntu-install-setup-php-curl/

If you use PHP, you may need to use cURL, which is one of the most popular extension. PHP CURL functions are available through the use of libcurl, a library created by Daniel Stenberg, and allow you to connect and communicate with web servers using many
different types of protocols.

Assume you have already setup LAMP. To install or setup cURL on your Linux machine like Ubuntu, run the following line of shell command in your terminal:

sudo apt-get install curl libcurl3 php5-curl

Now you have PHP cURL installed, the next thing you need to do is to restart apache2, run the following command in your terminal:

sudo /etc/init.d/apache2 restart

Wednesday, March 31, 2010

PHP Server Side Includes (SSI) - include() VS require()

Server Side Includes (SSI)

You can insert the content of one PHP file into another PHP file before the server executes it, with the include() or require() function.

The two functions are identical in every way, except how they handle errors:
  • include() generates a warning, but the script will continue execution
  • require() generates a fatal error, and the script will stop
These two functions are used to create functions, headers, footers, or elements that will be reused on multiple pages.

Server side includes saves a lot of work. This means that you can create a standard header, footer, or menu file for all your web pages. When the header needs to be updated, you can only update the include file, or when you add a new page to your site, you can simply change the menu file (instead of updating the links on all your web pages).

http://www.w3schools.com/PHP/php_includes.asp

Tuesday, February 16, 2010

PHP code tools round up

PHP code tools round up - Techworld.com

Though precise statistics are difficult to obtain, PHP is undeniably a top choice as a website building language. Since October 2009, the TIOBE Programming Community Index has PHP holding third place, behind Java and C, among programming languages overall. Regardless of the exact extent of PHP's usage, you need only consider that websites such as Facebook, which manages millions of users and petabytes of content, use PHP. Workloads of that magnitude demand a serious programming language and supporting environment.

In our estimation, four of these IDEs rise to the top. Zend Studio is an excellent PHP IDE once you become familiar with the Eclipse landscape. NuSphere's PhpED is also first rate and deserves your consideration if you need a professional-quality IDE and support. If you're on a budget or you can make it without technical support, Eclipse PDT and NetBeans are exceptional tools.

Thursday, February 11, 2010

How to Debug PHP Using Firefox with FirePHP

How to Debug PHP Using Firefox with FirePHP
July 11th, 2009 by Nuno Franco da Costa

Typically, there are two main ways of debugging server-side code: you can utilize an Integrated Development Environment (IDE) with a built-in debugger or log and perform your debugging processes in a web browser.

How to Debug PHP Using Firefox with FirePHP

This article shares an elegant, simple, and more maintainable way of debugging Ajax apps via the web browser (more specifically for the Mozilla Firefox browser). You'll learn the basics of leveraging Firefox in conjunction with Firebug and FirePHP to implement FirePHP libraries on web apps and logging messages in the Firebug console.

A Brief Introduction

When Ajax techniques became popular, developers faced a new problem: how can we debug Ajax requests and responses efficiently for complex web applications? If using a debugger was hard enough with the RESTful model, triggering an Ajax-specific request is a pain and a bit more difficult; dumping logs and information pertaining to those Ajax operations had to be done using JSON or XML.

A Brief Introduction

This is where FirePHP helps, allowing you to log your debugging messages to the Firebug console. FirePHP doesn't mess with your code (and it doesn't require you to modify anything to trap errors): the messages you print are sent to the browser in the HTTP response headers, which is great when you're using JSON or XML since it won't break their encoding.

This makes FirePHP ideal not only for debugging your Ajax requests, but also your entire PHP codebase.

So, what is FirePHP?

FirePHP is an add-on for an add-on: it extends the popular in-browser web development tool called Firebug with an API for PHP web application developers. FirePHP is free and easily attainable via the Mozilla Add-Ons section on the official Mozilla site. The official FirePHP site can be found via this web address: www.firephp.org. Christoph Dorn is the person responsible for creating FirePHP.

What Do I Need to Get Started?

As you might have guessed, you need three things to get up and running with FirePHP, they are:

  1. Firefox
  2. Firebug
  3. FirePHP

If you don't have all of the above applications installed on your machine, click on their link to learn about how to download them for your particular system.

Installation of the three things above is a straightforward process. FirePHP can be a little tricky to install if you've just recently started learning about web development, but there's good documentation out there about it.

This article is about using FirePHP, so I'll let you handle the installation part (though feel free to ask in the comments – we'd be happy to help if you encounter issues).

A Couple of Tips

Once you've installed FirePHP, and included it in your web application, you are ready to debug and log data. But first, I'd like to share two helpful tips I've learned:

Tip #1: call ob_start()

Because the information is sent to Firebug in the HTTP Headers, you should activate the output buffering or you might get the "headers already sent error". It may sound complicated, but all you have to do is write ob_start() on the first line of your PHP script that you're debugging.

Tip #2: don't forget to disable FirePHP Logging when you go live

You have to disable FirePHP when the site goes live or you will risk exposing sensitive information to anyone that has Firebug/FirePHP installed (we'll talk about how to do this later down the article).

And then just a general tip for Firebug/FirePHP users: it's also a good idea to disable or suspend Firebug and FirePHP when you're just browsing the web because they can really slow down some websites and web applications (such as Gmail, for example).

Getting Started with FirePHP Logging

This is the fun part where we start logging messages and reviewing the basic logging functions.

One thing to note is that, just like PHP, which (at least for PHP4 and PHP5) is a "pseudo object-oriented" language, you can use FirePHP in a procedural or object-oriented (abbreviated OO from now on) manner.

I prefer the object-oriented techniques and I encourage you to use the same pattern as it is considered the most popular and most modern approach to building apps.

The OO API allows you to instantiate a Firebug object to use it or to call its static methods directly. I'm a lazy guy and because static methods are more terse and require less typing, that's what I use.

Instantiating the OO API Object

In your script, you can use the following code block to create the FirePHP object ($firephp).

require_once('FirePHPCore/FirePHP.class.PHP'); $firephp = FirePHP::getInstance(true); $firephp -> [classmethod]

OO API with Static Methods

This is the format for calling static methods in your scripts.

require_once('FirePHPCore/fb.PHP'); FB::[nameofmethod] 

The Procedural API

Here's how to use FirePHP's Procedural API:

require_once('FirePHPCore/fb.PHP'); fb($var) fb($var, 'Label') fb($var, FirePHP::[nameofmethod])

We will not get into any detail about the benefits and coding style of each API, I've included them here only so you see what options are available for you. In other words, I don't want to start a flame war about which procedure is better – it's up to you to decide and I've noted my preference.

Logging Messages and Information in the Firebug Console

Let's talk about logging messages in the Firebug console (remember, this will only work if you've configured your app for FirePHP).

Examples of Basic Logging Calls

If you are ad-hoc debugging a bug, the following examples are what you'll be interested in utilizing.

Fb::log("log message")

This will print a string that you pass to it onto the Firebug console. Using the above example results in the following message:

Log message.

Fb::log($array, "dumping an array")

Passing an array (no more for loops or print_r() in your scripts) outputs the content of your array. The above example will result in the following message in the Firebug console:

Dump message array

Tip: when you hover your mouse on logged variables in the Firebug console, an info window will appear in the web page containing all of its elements. It's a nifty feature, don't you agree?

Variable Viewer

Logging an Information Message

Here is an example of logging information messages using the info method.

Fb::info("information")

This is the message it logs in your Firebug console:

info message.

Logging a Warning Message

Here is an example of logging a warning message.

Fb::warn("this is a warning")

This is the message it logs in your Firebug console:

Warning message

Logging an Error Message

Here is an example of logging a warning message using the info method.

Fb::error("error message") 

Here's what an error message looks like in the Firebug console:

Error message.

Enabling or Disabling FirePHP Logging

When your site goes live, you can (and should) disable FirePHP logging. Call the following line of code on the first lines of your script.

FB::setEnabled(false);

What's great about this is that you can leave all of your FirePHP code in your scripts for later use – just pass either true or false when you want to turn logging on or off.

If your application uses a "config file" to keep track of global settings, it is advisable to set a configuration option to enable or disable it.

Conclusion

First, here's a screen capture showing all of our messages in Firebug all at once (I ran it sequentially).

Conclusion: all together now

In this article, we covered the very basics of using FirePHP to help you debug and gain information about your PHP/Ajax applications easier and through the web browser. I hope that this results in you becoming convinced that you should explore your debugging options outside of "old-school" techniques such as using echo or print on top of your web page layout to see what a variable or array contains. Using FirePHP is so easy and convenient, and gives you much more options and data for debugging purposes.

In a future article, I'll be covering more complex features of FirePHP and using Firebug to make this simple debugging tool a more robust and fully-featured logging framework.

So stick around, don't forget to subscribe to the Six Revisions RSS feed so you get a note when that article is posted. * Article edits by Jacob Gube

Related content

About the Author

Nuno Franco da Costa is a web developer and sys admin. By day, he works at a design agency coordinating the development and sys admin teams where he developed a PHP MVC framework and a WEB 2 CMS. He loves to code and has a "getting things done" attitude. You can find over at his online presence www.francodacosta.com

Monday, February 1, 2010

How to check if string contains substring in PHP

How to check if string contains substring PHP

if $_SERVER['REQUEST_URI'] already contains a ? then using & instead
$HL_lnk = strpos($_SERVER['REQUEST_URI'],'?')?'&':'?';

------

Often, we see two approaches for this.

Option 1

One option is to use the strpos PHP function. The following example shows how this is used:

<?php
$pos = strpos($haystack,$needle);

if($pos === false) {
// string needle NOT found in haystack
}
else {
// string needle found in haystack
}
?>

Watch out, checking for substring inside string in PHP can be tricky. Some people do just something like

if ($pos > 0) {}

or perhaps something like

if (strpos($haystack,$needle)) {
// We found a string inside string
}

and forget that the $needle string can be right at the beginning of the $haystack, at position zero. The

if (strpos($haystack,$needle)) { }

code does not produce the same result as the first set of code shown above and would fail if we were looking for example for "moth" in the word "mother".

Option 2

Another option is to use the strstr() function. A code like the following could be used:

if (strlen(strstr($haystack,$needle))>0) {
// Needle Found
}

Note, the strstr() function is case-sensitive. For a case-insensitive search, use the stristr() function.

Which is Better?

The strpos() function approach is a better way to find out whether a string contains substring PHP because it is much faster and less memory intensive.

Any Word of Caution?

If possible, it is a good idea to wrap both $haystack and $needle with the strtolower() function. This function converts your strings into lower case which helps to eliminate problems with case sensitivity.

Thursday, December 17, 2009

php中?(问号)和:(冒号)的作用

php中?(问号)和:(冒号)的作用--Ajax中国

C语言里的语法,条件表达式e1?e2:e3,就是一个if语句的缩写,若e1为真(非0),则此表达式的值为e2的值;若为假,则表达式的值为e3。等同于
  1. $e="";
  2. if(e1)
  3. {
  4. $e=e2;
  5. }
  6. else
  7. {
  8. $e=e3;
  9. }

其中e1、e2、e3都是表达式, 如:

$shenhe=$val['available']?"已审核":"未审核"

Thursday, July 9, 2009

10 great ways to optimize your Wordpress blog

10 great ways to optimize your Wordpress blog
July 7, 1:06 PM

Creating an effective presence in the blogosphere has become far more competitive in recent years. With the steady growth of Facebook and Twitter, blogs are morphing into social media micro sites of their social network affiliates. I only host sites on Linux backed servers for performance and security purposes. Some of the following suggestions can only be applied in a LAMP environment (i.e. - askapache's .htaccess tweaks). Here are a few tips and plugins that I have found have worked quite well. I cannot take full credit for these so please make sure to check out the developers associated with each tweak for further information.

1. Install All-in-One SEO Pack by hallsofmontezuma and Google XML Sitemap plugin by Arne Brachhold. Post titles should appear before site name and sitewide keywords should mirror Google Adwords for relevant keyword searches. Also, regularly resubmit and update your xml sitemap and robot.txt files. I know this goes without saying, but it's something I sometimes forget to do.

2. Install Wp-Super Cache by Donncha O Caoimh. This will greatly speed up page load times. If you use firefox I would install ySlow to see where your site is prior to installation and your load time once you have gzip compression and page caching in place. To make this plugin even more effective check out Askapache's Hacking WP Super Cache For Speed. His re-writing of the .htaccess file has proven to be quite effective.

3. Make the most out of your .htaccess file - by enabling Gzip Compression, adding an Expires Header, and disabling ETags you can definitely give your Wordpress blog a needed boost. Here is a glimpse at some of the things I do with my .htaccess file.

# Use PHP5CGI as default AddHandler fcgid-script .php ##################################################### # Expires Header Header set Expires "Thu, 15 Apr 2010 20:00:00 EST" ##################################################### # Mod_Deflate <IfModule mod_deflate.c> <FilesMatch "\.(js|css)$"> SetOutputFilter DEFLATE </FilesMatch> </IfModule> ##################################################### # BEGIN WordPress SetEnv HTTP_IF_GZ_MATCH .html SetEnvIfNoCase ^Accept-Encoding$ "(.*gzip.*)" HTTP_IF_GZ_MATCH=.html.gz RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] RewriteCond %{ENV:REDIRECT_STATUS} !=200 RewriteCond %{QUERY_STRING} !s RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+)\ HTTP/ [NC] RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_|Facebook Connect API Number Here_user).*$ RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/%1/index%{ENV:HTTP_IF_GZ_MATCH} -f RewriteRule ^(.*)$ /wp-content/cache/supercache/$1/index%{ENV:HTTP_IF_GZ_MATCH} [L,NC] # END WordPress ##################################################### # CONFIGURE media caching Header unset ETag FileETag None Header unset Last-Modified Header set Expires "Fri, 21 Dec 2012 00:00:00 EST" Header set Cache-Control "public, no-transform" #####################################################

This accomplishes quite a bit and I also block out known malicious IP addresses for additional security.

4. Add a php opcode cache - eAccelerator and xCache are two popular systems. You need to have a good working knowledge of .ssh terminal commands in Linux and must have root access to your server to effectively utilize php optimization and opcode caching. This will help with your blogs ability to perform server-side php functions by creating a stored cache.

5. Make your Permalinks Pretty - SEF canonical urls are a no-brainer yet a lot of blogger still don't get it. I'm always surprised to find major corporate sites that have sloppy link structure.

6. Make your code Valid XHTML and CSS, consolidating Javascript and CSS into two files - This can be laborious, but it is essential. I am a big fan of semantic tableless CSS. However from what I have read and heard it seems that Googlebot and most other bots don't really have a problem indexing tables.

7. Write compelling content with solid back links and make sure to ping! - This is not really an optimization technique. It's more or less a pre-requisite. RSS snippets that leave your readers wanting more is important. Check out Searchengine Land's 25 Tips To Optimize Your Blog For Readers and Search Engines for more.

8. Deactivate unused plugins - There are several plugins I used every so often for maintenance purposes, but that don't serve an everyday purpose such as WP-DB Manager, DB Optimize, and Wp-Maintenance (to launch a quick maintenance splash page.)

9. Add rel=no follow to all sites you display in you link directory that have a page rank of 5 or less - This might be considered controversial, but to keep up with the big boys you have to pay careful consideration to who you back link to and why. Back links should fall into a related genre to what the mission your blog desires to achieve. Blogroll links need to also be site related.

10. Marry Facebook and Twitter on your blog - I encourage integrating the Facebook Connect API so users can login with their encrypted Facebook account and add a follow me on Twitter link either in your sidebar or at the bottom of your post page.

Including the Sociable social bookmarking plugin by Joost de Valk is also a suggestion. It's important to create meaningful footprints. If you provide relevant information that readers appreciate they will want to talk about it, share it, and thank you for it. It's pretty simple. Of course shamelessly self promoting your blog on Facebook and Twitter is a must! That is if you believe in what you write... I would like to thank askapache, Joost de Valk, and everyone else that contributes to making Wordpress a better and more reliable blogging platform. Their knowledge has helped me become better at what I do.

originally posted on 4 Darby Media Interactive May 4, 2009.

Saturday, May 30, 2009

用PHProxy实现虚拟主机做代理服务器

PHProxy is a web HTTP proxy programmed in PHP meant to bypass firewalls and access otherwise inaccessible resources (i.e. blocked websites). If the server this script is run on can access a resource, so can you!

The source code which runs PHProxy is available here.

Friday, May 29, 2009

AMFPHP and MySQL character set

sephiroth.it: Flash send and expects data from and to the outside world using unicode UTF-8 (see technote). The gateway.php file in AMFPHP folder is the bridge between your flash .swf file and your service php class.

You need to choose right parameters for the setCharsetHandler method to match your MySQL(server) and AMFPHP service class (client) environment.

You may also want to change client charset in your service PHP class:
mysql_set_charset() - Sets the client character set
mysql_client_encoding() - Returns the name of the character set

Saturday, May 23, 2009

Install AMFPHP on GoDaddy Hosting Site

I got all my information form the following 3 web pages, especially the first one:
1. Install the AMFPHP

First download the AMFPHP library, unzip it and then copy the amfphp folder to webserver. On my Linux hosting site this folder is
~/html/Sites/en.h.com/amfphp
and the URL is http://en.hycademy.com/amfphp. (delete the .htaccess file from this folder.) If everything is right, you will be able to test all the exposed PHP classes at: http://en.hycademy.com/amfphp/gateway.php

Then download StartingWithAMFPHP1.zip Use SQL script to generate tables in MySQL database. Extract all from PHP directory into AMFPHP service directory. In FLEX directory you can find a finished Flex project that you can import into your Flex workspace.

2. Create database

mysql -h dbname.dbhost.com -u username -p <amfphp.sql

3. Create PHP files
PHP service classes
~/Sites/en.h.com/amfphp/services/org/zgflex/cookbook/services/FlexAMFPHP.php
~/Sites/en.h.com/amfphp/services/org/zgflex/cookbook/services/SoccerManager.php
data objects
~/Sites/en.h.com/amfphp/services/org/zgflex/cookbook/dao/Player.php
~/Sites/en.h.com/amfphp/services/org/zgflex/cookbook/dao/Team.php

Please note, PHP script must have the same name as the class inside of it.

4. Create Flex project
Import the Flex project.

MXML application uses two remote objects, one is calling dummy PHP service and the other one works with the soccer data and helps you handle the data.

StartingWithAMFPHP.mxml

......

<mx:RemoteObject id="FlexAMFPHPService" source="org.zgflex.cookbook.services.FlexAMFPHP" destination="amfphp"
fault="faultHandler(event)" showBusyCursor="true">
<mx:method name="communicationTest" result="checkCommunicationHandler(event)" />
<mx:method name="checkAnotherMethod" result="checkCommunicationHandler(event)" />
</mx:RemoteObject>

<mx:RemoteObject id="SoccerService" source="org.zgflex.cookbook.services.SoccerManager" destination="amfphp"
fault="faultHandler(event)" showBusyCursor="true">
<mx:method name="getTeams" result="getTeamsHandler(event)" fault="faultHandler(event)" />
<mx:method name="updateTeam" result="updatedTeamHandler(event)" fault="faultHandler(event)" />
</mx:RemoteObject>

......

Just as you created PHP data class in Team.php, you need to create a simple mapping class in Actionscript. In this class you will store all the data and use it for handling data changes and sending the data back to the server. See Player.as and Team.as in Flex project folder: src/org/zgflex

You also need to configure services-config.xml file, and edit your URL to the AMFPHP gateway.php script.You have to use this XML file while the Flex project is compiled. You will do this by adding compiler parameter in project properties. Your compiler propetries should look something like this:

-locale en_US -services "services-config.xml"

Export the release build to bin-release folder and upload it to webserver's folder: ~/html/Sites/en.h.com/StartingWithAMFPHP/, and now you can access it at: http://en.hycademy.com/StartingWithAMFPHP/StartingWithAMFPHP.html

Working with Flex and PHP in Eclipse

From: Working with Flex and PHP in Eclipse | Adobe Developer Connection
By: Mihai Corlan

Developers who work with Flex and PHP can boost their productivity by combining two tools: Flex Builder and Zend Studio for Eclipse. This setup lets you create a combined project with Flex and PHP natures and reap the benefit of coding in both languages. (In Eclipse, natures link a project with specific builders and other settings.) The setup also enables you to debug your Flex and PHP code at the same time.

In this article I will show you how to install Flex Builder 3 together with Zend Studio for Eclipse, how to create a combined project, and how to debug a project that uses Zend AMF to send data between Flex and PHP.

Requirements

In order to make the most of this article, you need the following software and files:

Flex Builder 3 Eclipse Plug-in

Zend Studio for Eclipse

Zend Framework 1.7 or newer

Web server with support for PHP 5 or newer

Sample files:

  • flex_php.zip (ZIP, 445KB)
  • Note: You can import this archive using Import > Flex Builder > Flex Project.

Prerequisite knowledge

To benefit most from this article, it is best if you are familiar with Flex Builder, ActionScript 3.0, and PHP.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 Unported License.

Featured Post

Windows和Ubuntu双系统完全独立的安装方法

http://www.ubuntuhome.com/windows-and-ubuntu-install.html  | Ubuntu Home Posted by Snow on 2012/06/25 安装Windows和Ubuntu双系统时,很多人喜欢先安装windows,然...