because we are on the internet.

Archives for Program Your Site category

Learn PHP Programming

I have been learning php programming for a long time, and then I am thinking, how can I write PHP script much better, finally I decide to put all my php code in this webmaster blog.So that whenever I or somebody else need a reference, I or they can come back and just check the code, so as you will read, I will put some PHP code right here.

I write this post, because I need a php code list to finish my php codes, you can read them as follows:

PHP Basic:

  • PHP HOME
  • PHP Intro
  • PHP Install
  • PHP Syntax
  • PHP Variables
  • PHP String
  • PHP Operators
  • PHP If…Else
  • PHP Switch
  • PHP Arrays
  • PHP While Loops
  • PHP For Loops
  • PHP Functions
  • PHP Forms
  • PHP $_GET
  • PHP $_POST

PHP Advanced:

  • PHP Date
  • PHP Include
  • PHP File
  • PHP File Upload
  • PHP Cookies
  • PHP Sessions
  • PHP E-mail
  • PHP Secure E-mail
  • PHP Error
  • PHP Exception
  • PHP Filter

PHP Database:

  • MySQL Introduction
  • MySQL Connect
  • MySQL Create
  • MySQL Insert
  • MySQL Select
  • MySQL Where
  • MySQL Order By
  • MySQL Update
  • MySQL Delete
  • PHP ODBC

PHP XML:

  • XML Expat Parser
  • XML DOM
  • XML SimpleXML

PHP and AJAX:

  • AJAX Intro
  • AJAX PHP
  • AJAX Database
  • AJAX XML
  • AJAX Live Search
  • AJAX RSS Reader
  • AJAX Poll

PHP Reference:

  • PHP Array
  • PHP Calendar
  • PHP Date
  • PHP Directory
  • PHP Error
  • PHP Filesystem
  • PHP Filter
  • PHP FTP
  • PHP HTTP
  • PHP Libxml
  • PHP Mail
  • PHP Math
  • PHP Misc
  • PHP MySQL
  • PHP SimpleXML
  • PHP String
  • PHP XML
  • PHP Zip

PHP Quiz:

  • PHP Quiz
  • PHP Certificate

email() function in php

Hello guys,the email() function in php could be very useful to send emails.If we could use php to create email address and then we can use email() function to send mails to others.

Okay,here I just write some code,if you needed,you can use them.

You can create a file let’s say email.php and save all the code within the file.

<?php header(”Content-Type:text/html;charset=utf-8″); ?>
<?php
$s = 1000;////////////////$s stand for how many emails you want to create,I set it as 1000.

for($i = 1;$i <= $s;$i++){
$qqemail9 = rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . “@qq.com”;
$qqemail8 = rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . “@qq.com”;
$num = rand(1,2);
if($num = 1){
$to = “{$qqemail9}”;
$subject = “this is the subject”; //////////////////sent “this is the subject” with your subject.
$message = “this is the content” . ” \r\n “; //////////////////sent “this is the content” with your content.

echo $i . ” ” . $to . “<br />”;
mail($to, $subject, $message, “FROM: sender@sender.com”);////////sender@sender.com is your own address,you can change it to your own email address.
}elseif($num =2){
$to = “{$qqemail8}”;
$subject = “this is the subject”; //////////////////sent “this is the subject” with your subject.
$message = “this is the content” . ” \r\n “;//////////////////sent “this is the content” with your content.
echo $i . $to . “<br />”;
mail($to, $subject, $message, “FROM: sender@sender.com”);////////sender@sender.com is your own address,you can change it to your own email address.
}
}

echo “You have sent” . $s . “emails”;
?>

Just upload the email file to your hosting and open the file you will have 1000 emails sent.

Hello people,I just wrote a small php script to get the color of your webpage changed by second,and I just want to show it to you.

Here is the code:

<html>
<head>
<title>GET YOUR COLOR</title>
<meta http-equiv=”refresh” content=”1″>
</head>
<?php
$result = rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9);
?>
<body marginheight=”0px” marginwidth=”0px” bgcolor=”#<?php echo $result; ?>”>
<font color=”#FFFFFF” size=”+6″ style=”font-family:Arial, Helvetica, sans-serif “>
Backgroundcolor: #<?php echo $result; ?>
</font>
<table width=”100%” height=”100%”>
<tr>
<td>

</td>
</tr>
</table>
</body>
</html>

and here is a link,click it and you will see how to code works.

After connect php website and database,we will try to get the content from the database,we can create a page which is called content.php.

And we just need to put this code in the <body> </body> part.

<?php

$query_subjects = “SELECT * FROM subjects”;

$query = mysql_query($query_subjects);

if(!$query) {

die(”Database selection failed: ” . mysql_error() );

}

//so we just have get the content from the database subjects table,now we need to display the content on the website.

while($ subject_row = mysql_fetch_array($query)) {

echo $row[menu_name] ;

}

?>

It will get all the meun_name from the database and it will display on your website.

We just need to create a file config.php

and have the code

<?php

//Database Constants
define(”DB_SERVER”, “localhost”);
define(”DB_USER”, “english_wefri”);
define(”DB_PASS”, “winnerlabel”);
define(”DB_NAME”, “english_wefriend”);

?>

then create a file which is called connection.php

and put the code in the file.

<?php
require(”constants.php”);

// 1.Create a database connection
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if(!$connection){
die(”Database connection failed:” . mysql_error());
}

// 2.Select a database
$db_select = mysql_select_db(DB_NAME,$connection);
if(!$db_select){
die(”Database selection failed: ” . mysql_error());
}
?>

Then we just connect the our site to the database.

And we can put different kinds of code after that in the <head> & </head> as well as <body> </body> party.

After finish that we shall close the database,we just need to create another file which is called  footer.php

we just need to put the code

</div>
<div id=”footer”>Copyright 2007,Widget Corp</div>
</body>
</html>
<?php
if(isset($connection)){
mysql_close($connection);
}
?>

within the footer.php

so this three files help us with create a connection the our database and disconnect ourdatabase.

 

About Author

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum at arcu. Integer et risus. Morbi id tellus. Integer felis. Mauris malesuada, turpis vitae facilisis euismod, dui arcu adipiscing sem, eu vulputate leo ante in lacus. Sed porta accumsan lectus. Aenean ac sem. In consequat tempus velit. Phasellus leo enim, adipiscing a, egestas nec, pretium ut, pede. Mauris sollicitudin diam et mauris. Sed quis enim vel augue egestas lobortis. Etiam tempus ipsum vel neque.