Search Keyword:

web-folder-restrict

This is a simple quick tool to protect any given directory of your choice by limiting the users viewing and accessing the folder by specifying the IP addresses that can only access it in .htaccess

1. Open your text editor, copy and paste the following code:


AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "Example Access Control"
AuthType Basic
<LIMIT GET>
order deny,allow
deny from all
allow from 192.168.0.0
allow from 123.4.56.78
allow from 125.5.68.72
allow from 125.5.68.73
allow from 202.138.133.242
</LIMIT>


2. Replace the “allow from” lines to IP addresses that can access the folder/directory. These lines can only be one or can be many as you need.

3. Save the file as .htaccess

4. Upload to the root of the directory that you are trying to protect.

null


Date and time fields or what we call timestamps stored in our Mysql databases has a format of “YYYY-MM-DD HH:MM:SS” or “2011-04-15 11:30:00″ . It is awkward for the users to to see dates outputted to something in that format, so for user readability and friendly purposes, we must output the date into something more readable and understandable for them. There are 2 ways to accomplish this, formatting the date in our MySQL query before outputting, or grabbing the timestamp result from the query, then formatting it using PHP.

1. Formatting using MySQL’s DATE_FORMAT function


$result = mysql_query("SELECT DATE_FORMAT( date_field , 
             '%W, %M %e, %Y @ %h:%i %p' ) AS output_date FROM table");  
while ( $row = mysql_fetch_array($result) ) {
   
   echo $row['output_date'] . "<br />";
   // outputs something like "Friday, April 15 2011 @ 03:49:42 AM"

}

You can output different kind of date formats, not just the string format stated above. See other specifiers that can be used in the format string for Mysql in this link: http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_date-format

2. Formatting using PHP’s strtotime and date functions


$result = mysql_query("SELECT * FROM table");  
while ( $row = mysql_fetch_array($result) ) {
  
   $output_date = date("l, F j Y @ h:i:s A", strtotime($row["date"]));
   echo $output_date . "<br />";
   // outputs something like "Friday, April 15 2011 @ 03:49:42 AM"

}

You can output different kind of date formats, not just the string format stated above. See other specifiers that can be used in the format string for PHP in this link: http://php.net/manual/en/function.date.php

That’s it! It’s up to you on what kind of method you want to use in formatting your string. However, MySQL’s DATE_FORMAT function is not available in older versions of MySQL.

03Mar

Wordpress query hacks

Posted by admin as PHP, Wordpress

Sometimes, you need to get some information from your wordpress database and display it outside your WP application. Here are some useful custom queries that you can use to get data from your Wordpress database.

1. Get and display recent posts query.


//get recent posts function
$query = "Select * from wp_posts
          WHERE post_type = 'post'
          AND post_status = 'publish'      
          ORDER by post_date DESC
          LIMIT 0,5";
$result=mysql_query($query);

while($row=mysql_fetch_array($result)){
  echo "<li><a href='".$row['guid']."'>". $row['post_title'] . "</a></li>";
}

2. Get and display blogroll links query


//get blogroll links function
$query = "Select * from wp_links
    WHERE link_visible = 'Y'
    ORDER by link_name ASC";
    $result=mysql_query($query);

while($row=mysql_fetch_array($result)){
    echo "<li><a href='".$row['link_url']."'>". $row['link_name'] . "</a></li>";
}

3. Get and display categories query


//get category links function
$query = "Select object_id, wp_terms.name , wp_terms.slug from wp_terms
          inner join wp_term_taxonomy on wp_terms.term_id =
          wp_term_taxonomy.term_id
          inner join wp_term_relationships wpr on wpr.term_taxonomy_id =
          wp_term_taxonomy.term_taxonomy_id
          where taxonomy= 'category'
          order by object_id;";
$result=mysql_query($query);

while($row=mysql_fetch_array($result)){
    echo "<li><a href='category/".$row['slug']."'>". $row['name'] . "</a></li>";
}

4. Get and display pages query


//get pages links function
$query = " Select * from wp_posts
         WHERE post_type = 'page'
         AND post_status = 'publish'      
         ORDER by post_date DESC
         LIMIT 0,5 ";
$result=mysql_query($query);

while($row=mysql_fetch_array($result)){
    echo "<li><a href='".$row['guid']."'>". $row['post_title'] . "</a></li>";
}

Sponsored Links



Recent Comments

  • anup: thanx it helped me alot…
  • admin: try to look at window.location function of Javascript and place it under the success function of the AJAX...
  • ana: it works for me, but after success, how can i forward the url to a certain page? thanks
  • admin: Hello Don, do these steps again and again until the PSP reboots. Restore your PSP’s Default settings in SYstem...
  • don sb: my psp was already hacked then i changed the screen cos it broke,so at one point the battery lost total...