Archive for category PHP
XAMPP PHP cURL
cURL (Client for URLs) is in the XAMPP bundle. But you must enable it first before you can use it in your PHP code.
To enable curl library with XAMPP we need to modify the php.ini files in our xampp folder.
1. Locate some or all of the following files:
C:\Program Files\xampp\apache\bin\php.ini
C:\Program Files\xampp\php\php.ini
C:\Program Files\xampp\php\php4\php.ini
2. Uncomment the following line on your php.ini file by removing the semicolon.
;extension=php_curl.dll
3. Restart your apache server.
4. Check your phpinfo if curl was properly enabled.
Miss Universe goes Open Source

Miss Universe 2009
Miss Universe goes Open Source! The Miss Universe 2009 website was baked in CakePHP – the PHP MVC framework.
Check out the beauty of the CakePHP and the babes ;)
http://www.missuniverse.com/
Set Ubuntu up for Wake-on-LAN
To set up your Ubuntu system for Wake-on-LAN (WOL, WoL) is easy and straight forward.
1. Go to your BIOS, and turn on WakeOnLAN (it varies, look for it or one with similar name). If your network card is onboard, go to step 2b, otherwise, go to step 2a first.
2. Back in Ubuntu, Kubuntu, Xubuntu, we now need to write a script that will run every time the computer is on, because this command only lasts until the computer is turned on once again.
2a. Find out what network device you want to have the computer wake-able from, usually all, which is just one. If you have more network devices in your system, 9 chances out of 10, you already know what they are called.
You can NOT wake up a laptop or desktop that is only connected via wireless with Wake-on-LAN, unless the BIOS has a method for this, this is rarely the case, and I do not guarantee this will work in such cases.
In your terminal, type:
ifconfig
You’ll get something like: (I have removed my mac address for security)
eth0 Link encap:Ethernet HWaddr 01:23:45:67:89:ab
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::215:f2ff:fe6f:3487/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:71495 errors:0 dropped:0 overruns:0 frame:0
TX packets:76190 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:23164212 (22.0 MiB) TX bytes:7625016 (7.2 MiB)
Interrupt:217 Base address:0xd400
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1290 errors:0 dropped:0 overruns:0 frame:0
TX packets:1290 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:161182 (157.4 KiB) TX bytes:161182 (157.4 KiB)
So, I want this system to be ‘wakable’ from eth0.
2b. Now we create the script.
Take note that you must be an administrator of the system you are doing this to.
sudo -i
Enter your password at the prompt. Change to the startup script directory and start editing a new file:
cd /etc/init.d/ pico wakeonlanconfig
Paste or type this into the file, replacing eth0 with your network device, repeat the ethtool line as many times for your devices before the exit line:
#!/bin/bash ethtool -s eth0 wol g exit
Set the permission of the file:
chmod a+x wakeonlanconfig
Make the script run on startup:
update-rc.d -f wakeonlanconfig defaults
You should see the terminal responds with something like:
Adding system startup for /etc/init.d/wakeonlanconfig ... /etc/rc0.d/K20wakeonlanconfig -> ../init.d/wakeonlanconfig /etc/rc1.d/K20wakeonlanconfig -> ../init.d/wakeonlanconfig /etc/rc6.d/K20wakeonlanconfig -> ../init.d/wakeonlanconfig /etc/rc2.d/S20wakeonlanconfig -> ../init.d/wakeonlanconfig /etc/rc3.d/S20wakeonlanconfig -> ../init.d/wakeonlanconfig /etc/rc4.d/S20wakeonlanconfig -> ../init.d/wakeonlanconfig /etc/rc5.d/S20wakeonlanconfig -> ../init.d/wakeonlanconfig
Now we finish by running it, and making sure there is no error.
/etc/init.d/wakeonlanconfig
This should produce no output and put you right back at the prompt you started at.
3. Use it. you’ll need something to send Wake-on-LAN packets with, “wakeonlan” is in the repositories. And you’ll need the mac address of the system.
To get your MAC address, on the same system you just enabled WOL on, type:
ifconfig | grep HW
It is the thing that looks like 01:23:45:67:89:ab , write it down.
turn off that system:
sudo halt
If your using wakeonlan from the repositories, and you are on the same network as the computer your tying to wake up, replace 01:23:45:67:89:ab with your mac address and do, from another computer:
wakeonlan 01:23:45:67:89:ab
In most cases, you could send wake on LAN packets from a wireless connected computer.
If that doesn’t work, its likely the port on the system your trying to wake up isn’t the default (9), try 7, or if your BIOS settings or book told you one, use that one.
wakeonlan -p 7 01:23:45:67:89:ab
If that STILL doesn’t work, make sure wakeonlan is enabled in your BIOS and your hardware supports it.
PHP convert hour 24 to 12
In PHP, to do time formatting is very simple. If you have hour formatted in 24 hours format and you want to change it to a 12 hours format in am and pm, it is very easy. Below is an example to change 13:30 to 1:30 pm:
<?php time_in_12_hour_format = DATE("g:i a", STRTOTIME("13:30")); ?>
Hope this helps! ;)
Mirror Domain SEO
Many people want to know if mirror domain will affect SEO. If so, why some websites with good reputation use domain mirror. As many developers, I asked myself the same question when I was new to web development. Now after building, maintaining and upgrading many website, I gained some confidence to give my opinions.
A mirror domain is a server alias on the hosting server that allows you to access the same site content under more than one URL address. For example, you can have both a .com and a .net site that share the same site content.
A mirror domain can only “mirror” an existing account, as it is merely a server alias. A mirror domain is a “mirror” only in terms of address aliasing; it is not a physical mirror and there is no content duplication involved. Neither is it a “cloaking” or “domain gripping” facility.
So now it comes to WHEN you can mirror domain.
In many scenarios it is so much better to use a Redirect Domain if you want the same content accessible from different domains. This is where surfers to any alternative domains are automatically redirected to your primary domain, instead of seeing identical content at the alternative domains.
Almost all search engines will blacklist your domain if they find the exact same content at another domain, which will drop your site’s ranking very far down in their search results. If you want the same content accessible from different URLs, it is the best to use a Redirect Domain.
An example of when mirroring a domain doesn’t present a duplicate-content issue would be when unique content is dynamically generated or included based on the domain that’s requested.
simply put, consider the following PHP example:
<html> <head> <title><?php echo $_SERVER['SERVER_NAME']; ?></title> </head> <body> <h1><?php echo $_SERVER['SERVER_NAME']; ?></h1> </body> </html>
You can expand on that to include different templates, image directories, etc… based on the domain that’s requested.
So if you really need to display the exact same content on the same server, but you also care about duplicate content issues.
These examples assume that your domain is example.com, which is the one you care about seeing in the search results.
Option A uses the .htaccess file, and a second robots.txt file called robots2.txt, which includes the following:
User-agent: *
Disallow: /
Your regular robots.txt file should contain this, unless you have other entries you wish to keep:
User-agent: *
Disallow:
Then, put this in your .htaccess file, replacing example.com with your domain name:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/robots.txt$
RewriteCond %{HTTP_HOST} !^.*example\.com$
RewriteRule . /robots2.txt [L]
Option B uses PHP code that should either be placed in a common header file, or included in each page. This simply adds the robots meta-tag for the mirrors.
<html>
<head>
<title>Hardcoded Title That Doesn't Change</title>
<?php
if(!stristr($_SERVER['SERVER_NAME'], 'example.com')) {
echo '<meta name="robots" content="noindex,nofollow" />';
}
?>
</head>
<body>
Content goes here.
</body>
</html>
Make Ubuntu PHP Localhost Mail Function Work
Posted by admin in CakePHP, JavaScript Core, Linux, PHP Core on January 14, 2009
This article teaches you how to make Ubuntu PHP localhost mail function work, using PHP to send mail from localhost is easy. First, you need to install some PEAR mail packages.
In terminal, run the following command one by one:
sudo pear install mail
sudo pear install Net_SMTP
sudo pear Auth_SASL
sudo pear install mail_mime
After installing the pear packages, you need to install and configure postfix, first, run the following command to install postfix:
sudo apt-get install postfix
after installation, a configuration window will be displayed, you need to configure it:
Step 1: Choose Internet Site
Step 2: Enter localhost at the input area
For the rest of the steps, just follow the default settings. After complete the configuration, it’s time to test the PHP script. Create a PHP file called sendmail.php at your localhost, and copy and paste the code below into it (remember to change the email addresses to yours)
<?
include('Mail.php');
include('Mail/mime.php');
// Constructing the email
$sender = "shi <shichuanr@msn.com>";
$recipient = "Leigh <shichuanr@gmail.com>";
$subject = "Test Email";
$text = 'This is a text message.';
$html = '<html><body><p>This is a html message</p></body></html>';
$crlf = "\n";
$headers = array(
'From' => $sender,
'Return-Path' => $sender,
'Subject' => $subject
);
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
// Set body and headers ready for base mail class
$body = $mime->get();
$headers = $mime->headers($headers);
// SMTP params
$smtp_params["host"] = "localhost"; // SMTP host
$smtp_params["port"] = "25"; // SMTP Port (usually 25)
// Sending the email using smtp
$mail =&amp; Mail::factory("smtp", $smtp_params);
$result = $mail->send($recipient, $headers, $body);
if($result == 1)
{
echo("Your message has been sent!");
}
else
{
echo("Your message was not sent: " . $result);
}
?>
Now you should be able to receive the mail sent from your localhost. Good Luck! :-)
PHP Find Absolute Path
This article teaches you how to find absolute path using PHP. Open your notepad or any other text editor and put in the following PHP script:
<?php $p = getcwd(); echo $p; ?>
Save the file as path.php (or first as txt and rename to info.php) and upload it to the root directory of your site through ftp. Run it as http://yoursite.com/path.php and you have your absolute path.
Hope this helps! :-)
Make Drupal Localhost Mail Work
If you develop Drupal locally and try to use the PHP mail function, you may encounter problem. The PHP mail function cannot send mail out on your local system. To solve the problem, you can install a free local mail server on your computer, and test it locally.
First, read my another post here about how to install the local mail server.
After that, you can go to WordPress Admin area and change some of the user email to xxx@example.com, and you should be able to send mail in Drupal.
Hope this helps!
WordPress Mail Localhost
If you develop WordPress locally and try to use the mail function, you may encounter problem. The PHP mail function cannot send mail out. To solve the problem, you can install a free local mail server on your computer, and test it locally.
First, read my another post here about how to install the local mail server.
After that, you can go to WordPress Admin area and change some of the user email to xxx@example.com, and you should be able to send mail in WordPress.
Hope this helps!
PHP Mail Localhost
This article teaches you how to test PHP sent mail function on localhost.
1. On Windows, you can first download the free software Argosoft at (choose Mail Server Freeware):
http://www.argosoft.com/RootPages/Download.aspx
2. After downloading the software, double click to install it.
3. When launch the application, you should see something like the one below:
4. The port 80 might already be in use, because you may have Apache running on that port , click CTRL + O to configure new port for AMS web server. choose Ports tab. Change Web Interface port from 80 to anything you want, in this case, let’s try: 8087
5. Try point browser to the url below:
http://localhost:8087
You shall see something like the one below:
6. Now go back to the ArGoSoft window, and press CTRL+U, this will bring up something like the one below:
7. Click on Add user, and there should be a pop up window like the one below:
8. Set name and password, in this case, let’s set the username as sc.
9. Now close the user window, and press Ctrl+O, click on the local domains tab:
10. Add example.com
11. Now create a PHP file named send.php with script below:
mail('sc@example.com', 'My Subject', 'hullo world');
12. Run the send.php in your browser.
13. Now at http://localhost:8083, press Login, and enter username sc and the password you set.
14. You shall see your mail like something below:
Now it’s done! Hope this helps!



















































