Archive for the ‘PHP’ Category

Wordpress: ‘Recent Comments’ snippet

This item was filled under [ PHP, WordPress ]

A little piece of code that I found on BlogOhBlog.com. However, the code wasn’t doing proper formatting since all comments exceeding the sidebar width ended like the normal ones, so I simply added “..” at the end of lengthy comments. Also modified the display format to:
<Author> (on <PostTitle>):
<Comment text>
The code snippet can be used to [...]

Continue reading...

Get notified when Google crawls your website

This item was filled under [ PHP, SEO/Adsense ]

Ever wanted to know when Google crawls your website? Here is a simple PHP script which emails you whenever GoogleBot crawls your site.
<?php
if(strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false)
{
$email = 'you@domain.com';
mail($email,'Googlebot Alert', 'Googlebot has crawled your page: '.$_SERVER['REQUEST_URI']);
}
?>

Continue reading...

Executing PHP script from command line

This item was filled under [ PHP ]

Executing PHP scripts from command line is quite easy. You just need to know the right commands to execute your script. This procedure comes in handy while developing command line scripts.
*NIX OS:
/path/to/php -f /path/to/script.php
Windows OS:
X:\path\to\php.exe -f X:\path\to\script.php
-f parses and executes <file>. For a list of command line parameters, visit:
PHP: Using PHP from the command [...]

Continue reading...

Finding hostname from IP address

This item was filled under [ PHP ]

PHP has couple of network functions that come in handy. One of them is ‘gethostbyaddr‘. It returns the host name of the Internet host specified by ip_address (as defined by PHP.net).
<?php
echo gethostbyaddr("87.248.113.14");
?>
Alternately, you can find it through the ‘ping’ command:
> ping -a <ip>
The ping command will not work in case the firewall is enabled on [...]

Continue reading...

Integrating RoundCubeMail in your Website

This item was filled under [ PHP ]

To integrate *RoundCubeMail (for auto-login) in your own website, perform these two steps as defined on RoundCube Forum.
Edit your “index.php“..
1. Near line 240, modify the code as shown below:
// not logged in -> show login page
if (empty($USER->ID))
{
rcmail_login($_SESSION["www_user"], $_SESSION["www_pass"], $host);
if ($_task == "login")
header("Location: $RoundCubeDIR");
exit;
}
Here, $_SESSION variables contain value carried forward from your own website.
2. Now, update [...]

Continue reading...

Fixing attachment bug in RoundCubeMail

This item was filled under [ PHP ]

Often Word/Excel files do not appear in email message though the email contains attachment. I faced this issue using RoundCubeMail 0.1-stable. To fix it, simply download the updated version of PEAR MIME package from: http://pear.php.net/get/Mail_Mime
In your /program/lib/Mail/ directory, extract & replace with the new MIME package.
Try sending emails now, it should work properly!
*Actually [...]

Continue reading...

Managing AddressBook globally in RoundCubeMail

This item was filled under [ PHP ]

Setting up RoundCubeMail might require managing Contacts globally specially if you are working in an organization. There might be different tweaks available for this, but I got it done in a very simple manner.
Open up “func.inc” which can be found in: program/steps/addressbook/ directory. On line # 29, you will find:
$CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
Modify it [...]

Continue reading...

PHP: Replace string in TXT file

This item was filled under [ PHP ]

Ever wanted to search, replace string in TXT files? Use PEAR’s File_SearchReplace and it will do the task for you. You can get a copy of package from: http://pear.php.net/package/File_SearchReplace/
Its quite easy to use. Here is sample code from PEAR’s website:
<?php
include 'File/SearchReplace.php' ;
$files = array( "test1.txt",
"test2.txt",
"test3.txt" ) ;
$ignoreline = array( "#", ":") ;
$snr = new File_SearchReplace( [...]

Continue reading...

Executing SHELL commands with PHP

This item was filled under [ PHP ]

My last post discusses executing batch file in .Net. And the process does use couple of crappy .Net lines! But the same can be done with PHP only in 1 line
<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>
For more details, read here.

Continue reading...

PAMP: Personal Apache MySQL PHP

This item was filled under [ MySQL, PHP ]

[..] The new acronym is for Personal Apache MySQL and PHP (PAMP) is an experimental project by Nokia to provide an open source personal web server for their S60-based mobile phones.
You can install PAMP using PCSuite or simply by copying files to your memory card.
The downloaded package itself include Python, PythonScript Shell, Pips, Open SSL [...]

Continue reading...

Tagged with: [ , ]
Page 1 of 212»