Uploading Files—site administrators and content managers.

One useful piece of PHP functionality is support for uploading files. Instead of files
coming from the server to the browser using HTTP, they come from the browser to the server. This suits for site administrators and content managers.

First, your html sourse like this:(follow post i will put php code named upload.php)

<h1>Upload new news files</h1>
<form enctype=”multipart/form-data” action=”upload.php” method=post>
  <input type=”hidden” name=”MAX_FILE_SIZE” value=”1000000″>
  Upload this file: <input name=”userfile” type=”file”>
  <input type=”submit” value=”Send File”>



Using Basic Authentication

sometimes, when you get into a page then there a pop up window need your enter your name and password, here is the code, for authentication facilities are built into HTTP.

here is the code:

The user has not yet provided authentication information, it will be requested. If she has provided incorrect information, she is given a rejection message. If she provides a matching namepassword pair, she is presented with the contents of the page.


// if we are using IIS, we need to set

if ((substr($_SERVER[‘SERVER_SOFTWARE’], 0, 9) == ‘Microsoft’) &&
(!isset($_SERVER[‘PHP_AUTH_USER’])) &&
(!isset($_SERVER[‘PHP_AUTH_PW’])) &&
(substr($_SERVER[‘HTTP_AUTHORIZATION’], 0, 6) == ‘Basic ‘)
) {

explode(‘:’, base64_decode(substr($_SERVER[‘HTTP_AUTHORIZATION’], 6)));

// Replace this if statement with a database query or similar
if (($_SERVER[‘PHP_AUTH_USER’] != ‘user’) ||
($_SERVER[‘PHP_AUTH_PW’] != ‘pass’)) {

// visitor has not yet given details, or their
// name and password combination are not correct

header(‘WWW-Authenticate: Basic realm=”Realm-Name”‘);

if (substr($_SERVER[‘SERVER_SOFTWARE’], 0, 9) == ‘Microsoft’) {
header(‘Status: 401 Unauthorized’);
} else {
header(‘HTTP/1.0 401 Unauthorized’);

echo “<h1>Go Away!</h1>
<p>You are not authorized to view this resource.</p>”;

} else {
// visitor has provided correct details
echo “<h1>Here it is!</h1>
<p>I bet you are glad you can see this secret page.</p>”;

In the databases sourse: “shal(‘password’)” is strongest way protect your password.

Regardless of whether you store your data in a database or a file, storing the passwords as
plain text is an unnecessary risk.A one-way hashing algorithm can provide better security
with very little extra effort.
PHP provides a number of one-way hash functions.The oldest and least secure is the
Unix Crypt algorithm, provided by the function crypt().The Message Digest 5 (MD5)
algorithm, implemented in the function md5(), is stronger.

Stronger yet is the Secure Hash Algorithm 1 (SHA-1.) The PHP function sha1()
provides a strong, one-way cryptographic hash function.

use php and mysql create a page need user name and password

so ,you already set up your databases(in your databases already  had member), there add more then your could let your member log in.

after the form the follow codes use this instead

} else {
// connect to mysql
$mysql = mysqli_connect(“localhost”, “webauth”, “webauth”);
if(!$mysql) {
echo “Cannot connect to database.”;
// select the appropriate database
$selected = mysqli_select_db($mysql, “auth”);
if(!$selected) {
echo “Cannot select database.”;

// query the database to see if there is a record which matches
$query = “select count(*) from authorized_users where
name = ‘”.$name.”‘ and
password = sha1(‘”.$password.”‘)”;

$result = mysqli_query($mysql, $query);
if(!$result) {
echo “Cannot run query.”;
$row = mysqli_fetch_row($result);
$count = $row[0];

if ($count > 0) {
// visitor’s name and password combination are correct
echo “<h1>Here it is!</h1>
<p>I bet you are glad you can see this secret page.</p>”;
} else {
// visitor’s name and password combination are not correct
echo “<h1>Go Away!</h1>
<p>You are not authorized to use this resource.</p>”;

create database “auth” into mysql

here is the sourse for your databases

create database auth, there just create 2 users, you could create as many as you like, just insert the user name  and passwords. of course you also could create a page for page register into, following post i will write how to create a page insert data into mysql
use auth;
create table authorized_users ( name varchar(20),
password varchar(40),
primary key     (name)
insert into authorized_users values ( ‘username’,
‘password’ );

insert into authorized_users values ( ‘testuser’,
sha1(‘password’) );
grant select on auth.*
to ‘webauth’
identified by ‘webauth’;
flush privileges;

Create a php page that will process the order using an array and display the results on another page.

your html form must look like blown:

<form action=”hardware_order.php” method=”post”>
<legend>Order Form</legend>
<p><label for=”user”> Name</label> <input type=”text” name=”name” id=”user” /></p>
<p><strong>Select Some Products:</strong> <br>
<select name=”products[]” multiple>
<option value=”Sonic Screwdriver”>Sonic Screwdriver</option>
<option value=”Hammer”>Hammer</option>
<option value=”Drill”>Drill</option>
<option value=”Spanner”>Spanner</option>
<p><input type=”submit” name=”submit” value=”send”></p>

there are two ways can proceed this: one is :
$name =trim($_POST[‘name’]);
echo “nothing has been selected”;
echo “Thanks “.$name.” your select products is “;

foreach($_POST[‘products’] as $o)
echo $o.”<br/>”;
another ways is teacher’s answers:
$name =trim($_POST[‘name’]);
if (!empty($name))
{     echo “<p>Welcome <b>$name</b>!</p>”;
echo “<p>Enter a name</p>”;

echo “<ul>”;
echo “<p>Your product choices are:<br/>”;
foreach ($_POST[‘products’] as $value)
echo “<li>$value</li>”;
echo “</ul>”;
echo “<p> Nothing selected</p>”;


The Chinese Zodiac | a code demonstration for PHP

The Chinese Zodiac | a code demonstration for PHP

Chinese zodiac signs represent twelve different types of personalities. Traditionally beginning with the sign of the rat. Though the animal assigned for the birth year is not wholly who a person is, as there is also an animal assigned by the birth month called inner animals and by the birth hour called secret animals. These with a combination of five elements, make up 8,640 possible combinations for a persons personality trait, and all are considered important for the proper use of chinese astrology.

There are many versions of the story about the beginning of the zodiac, one such story begins with the rat being given the task on inciting the animals to report to the Jade Emperor to be selected for the zodiac. The cat being one of the animals selected was a good friend of the rat who tricked him into believing the banquet was a day later and the cat slept through it thinking it was not till the next day. When the cat found out he vowed to be the rats’ swore enemy for the ages.

use file store infomation to string

$outputstring = $date.”\t”.$tireqty.”\t”.$oilqty.” oil\t”.$sparkty.” spark plugs\t\$”.$totalamount.”\t”.$address.”\n”;

@$fp = fopen(“DOCUMENT_ROOT/../orders/orders.txt”,’ab’);

echo “<p><strong>Your order could not be process at this time. Please try again later.</strong></p></body></html>”;
fwrite($fp, $outputstring,strlen($outputstring));
flock($fp, LOCK_UN);

echo “<p>Order written.</p>”;

Loading Arrays from Files (use for loop)

$number_of_orders = count($orders);
if ($number_of_orders == 0){
echo ”

No orders pending.Please try again later.



for ($i=0;$i<$number_of_orders;$i++){

echo $orders[$i].”


Full stack developer