Sending Email (Text/HTML/Attachments)

Email is the most popular Internet service today. A plenty of emails are sent and delivered each day. The goal of this tutorial is to demonstrate how to generate and send emails in PHP.

So, you want to send automated email messages from your PHP application. This can be in direct response to a user’s action, such as signing up for your site, or a recurring event at a set time, such as a monthly newsletter. Sometimes email contains file attachments, both plain text and HTML portions, and so on. To understand how to send each variation that may exist on an email, we will start with the simple example and move to the more complicated.

Sending a Simple Text Email
Sending HTML Email
Sending Email with Attachments
Note that to send email with PHP you need a working email server that you have permission to use: for Unix machines, this is often Sendmail; for Windows machines, you must set the SMTP directive in your php.ini file to point to your email server.

Sending a Simple Text Email (more…)

Posted in Php Code. Comments Off on Sending Email (Text/HTML/Attachments) »

Blocking access to the login page after three unsuccessful login attempts

Sometimes you need to add an extra protection to password-protected website. This article explains how access to the login page can be restricted after three unsuccessful login attempts. This schema uses visitors IP address to store log attempts in the database and block access to login feature for 30 minutes after third unsuccessful attempt.

(more…)

Posted in Php Learning. Comments Off on Blocking access to the login page after three unsuccessful login attempts »

How to Get the Current Page URL

Sometimes, you might want to get the current page URL that is shown in the browser URL window. For example if you want to let your visitors submit a blog post to Digg you need to get that same exact URL. There are plenty of other reasons as well. Here is how you can do that. (more…)

Posted in Php Code, Php Skills, Php Study. Comments Off on How to Get the Current Page URL »

How to usp php to ban ip

First build a database table:

CREATE TABLE `su_lockip` (
  `id` int(4) NOT NULL auto_increment,
  `lockip` varchar(1024) default NULL,
  PRIMARY KEY  (`id`)
) 

Second, design a page so that you can add the ip you want to ban, every ip is devided by |,  I only write the mail part:
 

$UlockIp=$_POST[‘z’]?$_POST[‘z’]:”;
 if(empty($UlockIp)){
  exit(“<script>alert(‘Sorry, the message your input is wrong!’);history.back();</script>”);
 }
 $sql=”update su_lockip set lockip=’$UlockIp'”;
 if(mysql_query($sql)){
  exit(“<script>alert(‘Locked succesfully!’);history.back();</script>”);
 }else{
  exit(“<script>alert(‘Sorry, the message your input is wrong!’);history.back();</script>”);
 } 

Last, check the ip is in the database or not, if in the database, then show killed.

function lock_user_ip(){
 $Usql =mysql_query(“select * from su_lockip”);
 $Urs =mysql_fetch_array($Usql);
 $UlockIp=$Urs[‘lockip’];
 $ClockIp=$this->get_real_ip();
 $Iplist =explode(‘|’,$UlockIp);
 if(in_array($ClockIp,$Iplist)){
  exit(‘sorry system lock your IP’);
 }
 }
 
 function get_real_ip(){
   $ip=false;
   if(!empty($_SERVER[“HTTP_CLIENT_IP”])){
    $ip = $_SERVER[“HTTP_CLIENT_IP”];
   }
   if (!empty($_SERVER[‘HTTP_X_FORWARDED_FOR’])) {
    $ips = explode (“, “, $_SERVER[‘HTTP_X_FORWARDED_FOR’]);
    if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
    for ($i = 0; $i < count($ips); $i++) {
     if (!eregi (“^(10|172\.16|192\.168)\.”, $ips[$i])) {
      $ip = $ips[$i];
      break;
     }
    }
   }
   return ($ip ? $ip : $_SERVER[‘REMOTE_ADDR’]);
 } 

Posted in Php Code, Php Study. Comments Off on How to usp php to ban ip »

How to let tag cloud show the same size font and in list style?

It is very easy to tag cloud show the same size font and in list style, there are 2 ways to do this:

1. Change sidebar.php in templates:

<li>

<h2>Tag Cloud</h2>

<?php wp_tag_cloud(‘smallest=8&largest=8&number=45&orderby=name&format=list’); ?> <!– wp_tag_cloud(‘smallest=8&largest=8&number=45&orderby=name&format=list’)–>
</li>

another way is change code in widgets.php inside include document:

function wp_widget_tag_cloud($args) {
extract($args);
$options = get_option(‘widget_tag_cloud’);
$title = empty($options[‘title’]) ? __(‘Tags’) : apply_filters(‘widget_title’, $options[‘title’]);

echo $before_widget;
echo $before_title . $title . $after_title;
wp_tag_cloud(”); //wp_tag_cloud(‘smallest=8&largest=8&number=45&orderby=name&format=list’);
echo $after_widget;
}

Posted in Php Skills, WordPress. Comments Off on How to let tag cloud show the same size font and in list style? »

How to let the post show from lowest to highest?

If you want your posts show from lowest to highest, it is very simple, just add:
<!–p query_posts($query_string.’&order=ASC’);–>

for example, the following code will let all your post show from lowest to highest:

<!–p query_posts($query_string.’&order=ASC’);–>
<!–p if (have_posts()) : while (have_posts()) : the_post();–>

Posted in WordPress. Comments Off on How to let the post show from lowest to highest? »

List 50 posts of wordpress.

If you want to list 50 posts, use the following code:

<ul>
 <?php
 global $post;
 $myposts = get_posts(‘numberposts=-1’);
 foreach($myposts as $post) :
 ?>
    <li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
 <?php endforeach; ?>
 </ul>

if you want to list all the posts, use the following codes:

<ul>
 <?php
 global $post;
 $myposts = get_posts(‘numberposts=5’);
 foreach($myposts as $post) :
 ?>
    <li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
 <?php endforeach; ?>
 </ul>

http://codex.wordpress.org/Template_Tags/get_posts

Posted in Php Code, WordPress. Comments Off on List 50 posts of wordpress. »

WordPress Random posts

Display a list of 15 posts selected randomly by using the MySQL RAND() function for the orderby parameter value:

 <ul><li><h2>A random selection of kingphp posts</h2>
    <ul>
 <?php
 $rand_posts = get_posts(‘numberposts=15&orderby=rand’);
 foreach( $rand_posts as $post ) :
 ?>
    <li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
 <?php endforeach; ?>
    </ul>
 </li></ul>

 more: http://codex.wordpress.org/Template_Tags/get_posts#Random_posts

Posted in WordPress. Comments Off on WordPress Random posts »

How to get root dirctory by php

<?php echo realpath(‘./’)?>

very simple, right?

Posted in Php Code. Comments Off on How to get root dirctory by php »

Retrieve a Particular Post or Page

Retrieve a Particular Post
<?php
// retrieve one post with an ID of 5
query_posts(‘p=5’);     
?>
If you want to use the Read More functionality with this query, you will need to set the global $more variable to 0.

<?php
// retrieve one post with an ID of 5
query_posts(‘p=5’);
     
global $more;
// set $more to 0 in order to only get the first part of the post
$more = 0;

// the Loop
while (have_posts()) : the_post();
  // the content of the post
  the_content(‘Read the full post »’);
endwhile;
?>
Retrieve a Particular Page
To retrieve a particular page, you could use the following:

<?php
query_posts(‘page_id=7’);      //retrieves page 7 only
?>

or

<?php
query_posts(‘pagename=about’); //retrieves the about page only
?>

Posted in Php Code, WordPress. Comments Off on Retrieve a Particular Post or Page »
King Php Science Designed by:KingPhp.com Welcome, you are from: 54.146.11.8