Show or hide the page title in WordPress

Many of you have asked me a question how you hide the page title in WordPress, for example Home page. Some people don’t like to show the word “Home” right on frontpage. I tell you what; it’s not that difficult if you know how classes and functions work in this system. So this is what you should do to hide the title of the frontpage.

step 1) Go to directory /wp-includes/ in the root directory

step 2) Edit the function called function the_title($before = ”, $after = ”, $echo = true) in the file post-template.php

That’s it. You’re done. The rest will be taken care by HTML template of your selected theme.


How to block spam posts in your online forum

Most of you who own an online forum have already known much about spammers are trying to add bad posts, posts of links to porn websites, links to drugs, etc. I’m so tired of those who don’t respect my forum. So today, I’m gonna give you an instruction who to restrict those posts from entering to your professional forums. Since I added this logic in my online forum, I never see any bad post in the database any more.

Go to your forum root directory, pick the file called posting.php. First of all, you got to create a table of credible users in your database, example table is named tbl_users. The fields include just id (required), username (required), date_joined (optional). That’s all you need. Then copy my codes below and paste them to line 28 of your posting.php file. Remember to change the table “tbl_users” to the user table name in your database. The codes below will display a message and exit when there’s a user trying to post bad post to your forum. It only allows users who are credible (real users) in your tbl_users table.

//start
$aw_id = 0;
$getuser = $user->data[‘username’];
// check this username if it matches the username in separate member database to prevent hackers who post junks to your forums

$sql = “SELECT User_ID
FROM member_database.tbl_users
WHERE User_Name = ‘$getuser'”;

$result = $db->sql_query($sql);
$this_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

$aw_id = $this_data[‘User_ID’];
if($aw_id == ” || $aw_id == 0){
$box_t = ‘<div align=”center” style=”margin-top:50px;”><table cellpadding=”20″ style=”border:5px #027ab7 solid; background: #ecf3f7;”><tr><td>’;
$box_b = ‘</td></tr></table></div>’;
$message = ‘Our forum is only for licensed users. Please login to <a href=”http://www.yourdomain.com/login/”>www.yourdomain.com</a> and click on Forum icon to start posting a reply or a new topic.’;

exit(“$box_t$message$box_b”);
}
//end

The logic above has been tested on Windows and Linux servers. If you have issue implementing my codes, please call me at 1-415-845-0248 (Binh) I will help you after my working hours.


How to Execute an HTML Form Using JavaScript

Most of websites nowadays have at least one form. In general, the form is executed when a user presses a submit/send button. However, sometimes, you may need to submit the form programmatically using JavaScript without the interaction of a user. User wouldn’t even know because the JavaScript executes in the back-end.

JavaScript provides the form object that contains the submit() method. You will have to use the id or name of the form to get the form object.

For example, if the name of your form is ‘thisform’, the JavaScript code for the submit call is:
document.forms["thisform"].submit();

Here is the code to submit a form when a hyperlink is clicked:

<form name=”thisform” action=”process_form.php” method=”post”>
Search: <input type=’text’ name=’query’ />
<a href=”javascript: submitthisform()”>Search</a>
</form>
<script type=”text/javascript”>
function submitthisform()
{
document.thisform.submit();
}
</script>


What debugger is used to debug Drupal?

Since I’m working on module development and deals with so many websites during my projects, I found Xdebug is a great tool to debug Drupal modules. I am listing here step by step process to debug drupal using xdebug and Eclipse with your WAMP.

Download Eclipse PDT from here http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/…

Download php_xdebug-2.0.4-5.2.8.dll dll and place in C:\wamp\bin\php5.2.6\ext directory

Edit your php.ini file with the following code at the end of file.
[xdebug]
zend_extension_ts=”C:\wamp\bin\php5.2.6\ext\php_xdebug-2.0.4-5.2.8.dll”
xdebug.remote_enable=1
xdebug.remote_host=”localhost”
xdebug.remote_port=9000
xdebug.remote_handler=”dbgp”

Note: Carefully check the path and PHP version you’re using on zend_extension_ts line above.

Restart WAMP server.

If it’s successful installation of xdebug, when you view phpinfo.php, you will find the lines below:

Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
with Xdebug v2.0.4, Copyright (c) 2002-2008, by Derick Rethans

Open your Eclipse and add the drupal folder as php project. Todo this just create an emty php project and give the project workspace as c://wamp/www and add import your existing drupal folder to this project as a general folder import in eclipse.

Open Window->Preferences->General->Web Browser and set your browser as external browser and select any of your browser.

Then go to Window->Preferences->PHP->Debug, set PHP Debugger option to XDebug

Next select your index.php -> right click -> Debug as -> Php webpage. Now your defined browser will open and you can see your project is running.

Now go to Window -> open Perspective -> PHP debug. You can see code is halted at first line of code. If you press play button in green color, your codes will execute.

Set break points wherever you want in the files and click on step into to see the code flows.

To make module files open in Eclipse, you must add extensions to *.module to window->preferences->general->editors->file associations file type such as *.module, *.engine, *.inc and associated editor as PHP

Please leave a comment for this article if you encounter any issue during the installation and debugging. I hope that this article helps you.


How to get an IP address of a visitor to your website using PHP?

Sometimes you will want to know the IP address of any visitor to your website for marketing analysis, or for sales chart purposes, or for geo location analysis of your website visitors.  By using PHP, finding an IP address nowadays is much easier. It is very important requirement for many scripts where we store the members or visitors details. For security reason we can store IP address of our visitors who are doing any purchases or recording the geographical location of the visitor can be done this way. Sometimes based on the IP address we can redirect the browser to specific location of the site. For example, your website has advertisement banners that only targets users in San Francisco. When a visitor visit your website, you’ll record their IP address and then from there your codes will know that this visitor is in San Francisco. Therefore, an ad banner about San Francisco restaurant or hotel will be displayed on the page. There are many applications using this and below is the PHP code to recognize the IP address of any visitor of your web site.

If register_global in your php.ini is on, your codes on php page will be:

$ip=@$REMOTE_ADDR;
echo “IP Address is $ip”;

You will see this:
IP Address is 209.31.236.130

If you have a geo location by IP Lookup DB, you will find out that this sample IP address is in San Jose.

If register_global is off, your codes on php page will be:

$ip=$_SERVER[‘REMOTE_ADDR’];
echo “IP Address is $ip”;
You will see the same output as the above. With this piece of data, you can save it in your database table and redirect to an ads that targets users in this location. Or you can display a local community news for this user.

I hope that my explanation about IP address helps you in making decision for your website advertisement or your blogs.