Showing posts with label to. Show all posts
Showing posts with label to. Show all posts

Sunday, July 3, 2016

Pre requisites to learning PHP and MySQL

Pre-requisites

Before you continue you should have a basic understanding of the following:

  • HTML/XHTML
  • JavaScript

What is PHP?

  • PHP stands for PHP: Hypertext Preprocessor
  • PHP is a server-side scripting language, like ASP
  • PHP scripts are executed on the server
  • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)
  • PHP is an open source software
  • PHP is free to download and use

What is a PHP File?

  • PHP files can contain text, HTML tags and scripts
  • PHP files are returned to the browser as plain HTML
  • PHP files have a file extension of ".php", ".php3", or ".phtml"

What is MySQL?

  • MySQL is a database server
  • MySQL is ideal for both small and large applications
  • MySQL supports standard SQL
  • MySQL compiles on a number of platforms
  • MySQL is free to download and use

PHP + MySQL

  • PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform)

Why PHP?

  • PHP runs on different platforms (Windows, Linux, Unix, etc.)
  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)
  • PHP is FREE to download from the official PHP resource: www.php.net
  • PHP is easy to learn and runs efficiently on the server side

Where to Start?

To get access to a web server with PHP support, you can:

  • Install Apache (or IIS) on your own server, install PHP, and MySQL
  • Or find a web hosting plan with PHP and MySQL support

PHP Installation

What do you need?

Most people would prefer to install a all-in-one solution:

WampServer 2.0i [07/11/09] ? for Windows platform Includes : - Apache 2.2.11 -

MySQL 5.1.36 - PHP 5.3.0

http://www.wampserver.com/en/

http://lamphowto.com/ for Linux platform

Already have a web server?

If your server supports PHP you dont need to do anything.

Just create some .php files in your web directory, and the server will parse them for you. Because it is free, most web hosts offer PHP support. However, if your server does not support PHP, you must install PHP. Here is a link to a good tutorial from PHP.net on how to install PHP5:

http://www.php.net/manual/en/install.php

Download PHP

Download PHP for free here: http://www.php.net/downloads.php

Download MySQL Database

Download MySQL for free here: http://www.mysql.com/downloads/index.html

Download Apache Server

Download Apache for free here: http://httpd.apache.org/download.cgi

Download a nice text editor

http://www.flos-freeware.ch/notepad2.html

Thursday, June 30, 2016

Google PageRank PHP Script An Easy To Use And Working! PHP Script To Find Google PageRank Of Any Website

A very simple and powerful PageRank (Google PageRank) finder for any website. Just submit the website URL one at a time and get the page rank. Script is using Google toolbar to get the PageRank. 
Google PageRank PHP script works for both Bloggers and Webmasters. This script directly communicates with the Google toolbar.So it always is advisable not to make too many request at the same time from the same IP.

Instructions

Download "Download Free PHP pagerank script" and extract it using winzip or other similar program.

Include google-pagerank.php in your PHP which is going to display the pagerank for a website.

<?PHP include_once "google-pagerank.php"; ?> 

In the next line,

<?PHP
$url = "http://google.com";
$width = "200";
$method = "css"; //image or css or default
$image_location = "images/"; //including the slash (/)
$obj = new pr($url,$method,$width,$image_location);
?>

Thats it. Now all we have to do is, display the pagerank in the desired position of your webiste.

<p><PHP echo $obj->pagerank(); ?></p> 

If you are using "css" or "default", you have to use the above method to display the pagerank image."images" method requires the following line of code.

<p><img src="filename.php" /></p> 
filename.php should contain

<? include_once("google-pagerank.php");
$url = "http://www.google.com;
$width = "";
$method = "image"; //image
$image_location = "images/"; //including the slash (/)
$obj = new pr($url,$method,$width,$image_location);
echo $obj->pagerank();
?>
Instruction For Bloggers:

Bloggers cant use PHP code in blogs. so to display pagerank in your blog use the following code.

<p><a href=""><img src="http://www.agrizlive.com/
demo/google-pagerank-script/blogger.php?
url=http://www.google.com" /></a></p>

 Make sure you replace the blue color http://www.google.com to your blogger URL.

Download Google PageRank PHP Script


Wednesday, June 29, 2016

How to Code Your Own CAPTCHA Script In PHP

Today I will show you how to code your own CAPTCHA Script.
<?php
session_start();
$strlength = rand(4,7);

for($i=1;$i<=$strlength;$i++)
{
$textornumber = rand(1,3);
if($textornumber == 1)
{
$captchastr .= chr(rand(49,57));
}
if($textornumber == 2)
{
$captchastr .= chr(rand(65,78));
}
if($textornumber == 3)
{
$captchastr .= chr(rand(80,90));
}
}
$randcolR = rand(100,230);
$randcolG = rand(100,230);
$randcolB = rand(100,230);

/initialize image $captcha is handle dimensions 200,50
$captcha = imageCreate(200,50);
$backcolor = imageColorAllocate($captcha, $randcolR, $randcolG, $randcolB);

$txtcolor = imageColorAllocate($captcha, ($randcolR - 20), ($randcolG - 20), ($randcolB - 20));
for($i=1;$i<=$strlength;$i++)
{

$clockorcounter = rand(1,2);
if ($clockorcounter == 1)
{
$rotangle = rand(0,45);
}
if ($clockorcounter == 2)
{
$rotangle = rand(315,360);
}

//$i*25 spaces the characters 25 pixels apart
imagettftext($captcha,rand(14,20),$rotangle,($i*25),30,$txtcolor,"/arial.ttf",substr($captchastr,($i-1),1));
}
for($i=1; $i<=4;$i++)
{
imageellipse($captcha,rand(1,200),rand(1,50),rand(50,100),rand(12,25),$txtcolor);
}
for($i=1; $i<=4;$i++)
{
imageellipse($captcha,rand(1,200),rand(1,50),rand(50,100),rand(12,25),$backcolor);
}
//Send the headers (at last possible time)
header(Content-type: image/png);

//Output the image as a PNG
imagePNG($captcha);

//Delete the image from memory
imageDestroy($captcha);

$_SESSION[captchastr] = $captchastr;

?>
If you like this script then feel free to Subscribe to our blog and we will email you similar interesting and useful PHP scripts in your Inbox as soon as it is published on our blog.

Enjoy!


How To Get Current URL Without Page Name In PHP

Today I will share a code snippet which will help you get a current URL Without Page Name.

<?PHP

function getPath() {
$protocol = strpos(strtolower($_SERVER[SERVER_PROTOCOL]),https) === FALSE ? http : https;
$host = $_SERVER[HTTP_HOST];
$path = substr($_SERVER[SCRIPT_NAME], 0, -strlen(basename($_SERVER[SCRIPT_NAME])));

return $protocol.://.$host.$path;
}

echo getPath();

?>

This simple piece of code will do the trick.

If you want more such tips and tricks related to PHP then consider subscribing to our blog.

Enjoy!


Monday, June 27, 2016

Upload Form PHP Script A PHP Script Which Will Enable You To Upload Files On Your Site

A very simple php script.Simple file upload form for your site.

Features:
  • Limit file types available for upload
  • Maximum file size validation
  • Can rename file after upload to avoid URL guessing
  • Log of uploads can be saved in MySql database. Log includes Filename, file size, IP of the user, date of upload
 Download Upload Form PHP Script

Email Errors To Yourself Instead Of Showing It Publicly

Most servers are set to display an error message when an error occurred in one of your script. But, you may also want to get an email containing the error, instead of displaying it to the public.

The Script is given below:

<?php

// Our custom error handler
function nettuts_error_handler($number, $message, $file, $line, $vars){
$email = "
<p>An error ($number) occurred on line
<strong>$line</strong> and in the <strong>file: $file.</strong>
<p> $message </p>";

$email .= "<pre>" . print_r($vars, 1) . "</pre>";

$headers = Content-type: text/html; charset=iso-8859-1 . " ";

// Email the error to someone...
error_log($email, 1, you@youremail.com, $headers);

// Make sure that you decide how to respond to errors (on the users side)
// Either echo an error message, or kill the entire project. Up to you...
// The code below ensures that we only "die" if the error was more than
// just a NOTICE.
if ( ($number !== E_NOTICE) && ($number < 2048) ) {
die("There was an error. Please try again later.");
}
}

// We should use our custom function to handle errors.
set_error_handler(nettuts_error_handler);

// Trigger an error... (var doesnt exist)
echo $somevarthatdoesnotexist;
 
Hope You Enjoyed Reading this Post.

Search Engine Submission PHP Script Use this Script to Submit a Website to 130 Search Engines

URL Submit Script is PHP script which allows users to submit website to over 130 Search Engines at one go, no waste of your time as just in one click your site will be listed in the most important Search Engines.
You can also use this PHP Script to offer a service to all the visitors on your Site/Blog.

Installations:

  • unzip all files in a folder!
  • send all files from your server

Features:

  • Install in 1 minute
  • Offer service for your visitors
  • Language file ( easy to translate )
  • Easy add or remove engines ( flat file )

Requirements:

  • PHP 4.2+
  • Ioncube loaders

Some FAQs:

Q: How Do I Install URL Submit Script?

A: unzip all files and send to your server , if you dont like the design, you can change the design to suit your taste.All CSS are in index.php, if you do not want to change then include it in your actual site using include function example:
<?php include("submit.php");?>
Q: How to solve ioncube error ?

A: If you are running different PHP version, download the loader from your system here http://www.ioncube.com/loaders.php and add it in your ioncube folder.

Q: How to add or remove engines ?

A: open file @@@_engines.txt , one engine per line , if you like to remove a Search Engine, only remove the line and its done,Search Engine is no more available, if you like to add a Search Engine, all values are separated by |
Example :
 number unique|name display|main url |path |answer to know if have a error or success |keep 1 |.

 Download Search Engine Submission PHP Script

Saturday, June 25, 2016

How to Create Drop Down Menu using CSS3 and JQuery

Today i would like to show, How to Create Drop Down Menu using CSS3 and jQuery. Designing a Simple Drop Down Menu with HTML by Implementing CSS and jQuery is very easy to create. A simple horizontal menu that shows it’s sub menu on mouse hover. when you hover a mouse on main link it will show it’s sub menu. just take a look at this tutorial.
How to Create Drop Down Menu using CSS3 and JQuery
Read more »

Saturday, June 18, 2016

Using the static Statement to Remember the Value of a Variable Between Function Calls


If you declare a variable within a function in conjunction with the static statement, the variable remains local to the function, and the function "remembers" the value of the variable from execution to execution





<?php
function numberedHeading($txt) {
static $num_of_calls = 0;
$num_of_calls++;
echo "<h1>".$num_of_calls." ". $txt."</h1>"; }
numberedHeading("Mobile Phones");
echo "<p>We build a fine range of mobile phones.</p>";
numberedHeading("Camera");
echo "<p>Also Digital Cameras..</p>";
?>

The numberedHeading() function has become entirely self-contained. When we declare the $num_of_calls variable on line 3, we assign an initial value to it. This assignment is made when the function is first called on line 7. This initial assignment is ignored when the function is called a second time on line 9. Instead, the code remembers the previous value of $num_of_calls. We can now paste the numberedHeading() function into other scripts without worrying about global variables.

Friday, June 17, 2016

How to Select Deselect all Checkboxes with jQuery

In this tutorial i am going to explain you that how to do “Select / Deselect all checkboxes using jQuery”, Most of newbie learners face this issue that how to select all and deselect all checkboxes of any needable forms , this one is simple script but yet useful, hence we can also select checkbox values individually but we frequently need this type of snippets to perform multiple operations, like gmail you can select all emails and perform any operations it have, so this will guide you that how to use jQuery to select and deselect all checkboxes, and at the end of this tutorial we will also see that how to get selected (multiple) checkboxes value and print them so have a look.

How to Select all / Deselect all Checkboxes with jQuery
Read more »

Monday, June 13, 2016

Restricting admin page to be accessed from only certain ip addresses

If you want to apply someting more secure than just a password to access your admin page you can restrict your admin page to be accessed from only one ip address.

First you should know your ip address. If you dont know you can run this script: 
  <?php
  echo "IP anda : " . $HTTP_SERVER_VARS[REMOTE_ADDR];
?>

Then in the admin area, for example in "administrator/index.php", insert this script on the topmost:

<?php
  $ip = "127.0.0.1" // your ip
  if($HTTP_SERVER_VARS[REMOTE_ADDR] != $ip) {
  header("location: ../index.php");
  } else {
  Setcookie("ip",$ip); }
?>

Then for each file in the admin area, insert this script:

<?php
  $ip = $_COOKIE[ip]; // call cookie ip
  if($HTTP_SERVER_VARS[REMOTE_ADDR] != $ip) {
  echo "You dont have right to access this page!";
  } else {
  // your menu here
  }
?>

Please remember to call cookies or session for your admin username and pasword as well. The example above only call cookie for ip address. 

You may want to apply more than one ip address and store the ip address list in database as following:

CREATE TABLE `web`.`tb_admin` (
  `id` BIGINT( 20 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  `ip` VARCHAR( 30 ) NOT NULL
  ) 
 
  INSERT INTO `web`.`tb_admin` (  `id` ,  `ip`  )
  VALUES (1 , 127.0.0.1);

Config.php
<?php
$host = "localhost";
$user = "root";
$pass = "";
$konek = mysql_connect($host,$user,$pass) or die("Check host,user,or password");
$select_db = mysql_select_db("web");
?>

Then in the index.php in the admin folder, you can insert this script:

index.php

<?php
  include("config.php");
  $ip = $HTTP_SERVER_VARS[REMOTE_ADDR];
  $valid_ip = mysql_query("SELECT * FROM tb_admin WHERE ip=$ip");
  if (!= $valid_ip) {
  echo "You dont have permission to access this page!";
  } else {
  // your menu goes here...
  }
?>


How to Create Pagination with PHP PDO using OOP

In this tutorial we will see that how to create Pagination with PHP, PDO using OOP concept, when we have number of records in database then we must Paginate the data, this is very Simple tutorial using PDO and OOP without using Ajax or jQuery it is based on pure PHP, i have created one class file using that class file you can make Pagination of database records and this class file featured with next and previous links based on the page.
How to create Pagination with PHP, PDO using OOP
Read more »

Wednesday, June 8, 2016

How to Send e Mail using PHPMailer and Gmail SMTP

hello friends after a long time i'm going to post a simple yet useful post here about SMTP mails, i received few email requests from my readers to post email verification feature in my login and registration tutorial i'll post email verification tutorial after this post this was first step to send emails from localhost and online server as well for that you have to use PHPMailer library, so take a quick a look at this tutorial to understand "how to send SMTP mails using PHPMailer"
How to Send e-Mail using PHPMailer and Gmail SMTP
Read more »

Tuesday, June 7, 2016

How To Use PHP Data Object PDO Tutorial

In this tutorial i want to explain about PDO(PHP Data Objects), this is another and awesome method to interact with MySQL database, PDO are different from the old procedural method and it is improved MySQL extension, and nowadays most of PHP programmers uses PDO extension instead of old MySQL, so I’m going to create here CRUD operations using PDO, It’s easy to create and handle such operations with database using PDO and how to use PDO functions lets see it in detail.
How to use PHP Data Object - PDO Tutorial
Read more »

Sunday, June 5, 2016

How To Code A Simple Calculator In PHP

In this php tutorial you will learn how to make a simple PHP calculator
<?php

if($submit)
{
if($operator == *)
{
echo $numa * $numb;
} elseif($operator == /)
{
echo $numa / $numb;
} elseif($operator == +)
{
echo $numa + $numb;
} elseif($operator == -)
{
echo $numa - $numb;
}
} else { ?>
<form method="POST" action="<?php $_SERVER[PHP_SELF]; ?>">
<input type="text" name="numa" size="10">
<select name="operator">
<option value="+">Add</option>
<option value="-">Subtract</option>
<option value="*">Multiply</option>
<option value="/">Divide</option>
</select>
<input type="text" name="numb" size="10">
<input type="submit" value="Calculate" name="submit">
</form>
<?php } ?>
If you have any suggestions regarding the script please feel free to share it with us.Feel free to edit the above script to suit your personal needs.

Subscribe to our blog and we will email you similar interesting php scripts as soon as it is published.

Beside you could also refer to our PHP Interview Questions Series.

Enjoy!

Saturday, June 4, 2016

Redirect To Another Page In PHP Without Using Header

A little bit of Javascript might help you to rediect to another page.A sample code is given below:

<?php

// show some bits
printf("<html><body>");
printf("Just some bits on this page...");

// do your condition based tests
.....

if ($myConditions != $meetsExpectation)
{
printf("<script>location.href=errorpage.html</script>");
}
else
{
// show other stuffs
}
?>
Hope this leads you in the right diection.Though there are many other ways of doing it,this appears to be the simplest one,isnt it?

If you like this php script the please subscribe to our blog and we will send you updates from this blog right in your Inbox.

Enjoy!

Friday, June 3, 2016

VDaemon PHP Library To Check User Input For Errors

An important aspect of creating Web Form pages is to be able to validate that the information users enter is correct. Handling errors in a Web Forms is a mandatory task for any true professional. It is not a difficult job to write this on PHP or JavaScript, but writing this more than once can quickly become a tedious nightmare.

What is VDaemon?

VDaemon is a PHP library that grants an easy-to-use but powerful way to check user input for errors, and, if necessary, display messages to the user.

What can VDaemon do?

  • VDaemon PHP script performs server-side validation using PHP and client-side validation using JavaScript.
  • VDaemon can perform wide range of validation tasks. It includes mandatory fields validation, validation for properly formatted value (currently supported types are e-mail address, zip codes for US, Canada and UK, US phone number, IP address, date and time in various formats, integer and floaf numbers, currency), comparing entered value to the predefined value or to another form element value, validating against regular expression pattern and more.
  • VDaemon allows combining validation rules into logical expressions of any complexity. It gives possibility to create a conditional validation.
  • VDaemon allows to highlight invalid form elements and/or corresponding labels by assigning them an alternative CSS styles. It automatically sets focus to the first invalid form element.
  • VDaemon can collect and display all error messages in one place on a page.
  • VDaemon leaves the behaviour of HTML forms unchanged. This allows easy incorporation of VDaemon validation into existing web sites.
  • VDaemon produces XHTML compliant code.
  • And more ...
Requirements

PHP version 4.2.0 or later is required for server-side validation.

Client-side validation is supported for the following browsers:
- IE 5 and later
- Firefox 1.0 and later
- Opera 7 and later
- Netscape 7 and later
- Safari 2.0 and later

Download VDaemon PHP Script

Thursday, May 26, 2016

Code A Simple PHP Contact Form With A Reply To Option

Today I will show to how to code a Contact form in PHP Which also has a Reply To feature.It is very simple to do so using combination of HTML and PHP.

The Code for the form is given below:

Form Code:
<form action="procesar_form.php" method="post" name="formulario" id="formulario" onsubmit=return validarFormulario()>
<label for="nombre">Nombre </label>
<input type="text" name="nombre" id="nombre" size="60"/>

<label for="apellido">Apellido </label>
<input type="text" name="apellido" id="apellido" size="60"/>

<label for="email">Email </label>
<input type="text" name="email" id="email" size="60"/>

<label for="comentarios">Comentarios</label>
<textarea name="comentarios" id="comentarios" cols="44" rows="10"></textarea>

<input type="button" name="enviar" id="enviar" value="Enviar" onclick="validarFormulario()" /></textarea>

</form>

PHP Code
$email = $_POST[email];


$to = xyz@gmail.com;
$subject = Contacto Us;
$message = Name: . $_POST[name] . " " .
Surname: . $_POST[surname] . " " .
Email: . $_POST[email] . " " .
Comments: . $_POST[comments];
$headers = From: $email . " " .
Reply-to: $email . " " .
X-Mailer: PHP/ . phpversion();


mail($to, $subject, $message, $headers);


header("Location: ../../index.html");

Just put it all together and you are ready to go.I hope you enjoyed this free php script

Enjoy!

Tuesday, May 24, 2016

PHP Script To Parse Out Common Phrases In A Document

Today I will discuss with you a function written in PHP which will enable you parse out common phrases in a document.
function getPhraseCount($string, $numWords=1, $limit=0) {
// make case-insensitive
$string = strtolower($string);
// get all words. Assume any 1 or more letter, number or in a row is a word
preg_match_all(~[a-z0-9]+~,$string,$words);
$words = $words[0];
// foreach word...
foreach($words as $k => $v) {
// remove single quotes that are by themselves or wrapped around the word
$words[$k] = trim($words[$k],"");
} // end foreach $words
// remove any empty elements produced from trimming
$words = array_filter($words);
// reset array keys
$words = array_values($words);
// foreach word...
foreach ($words as $k => $word) {
// if there are enough words after the current word to make a $numWords length phrase...
if (isset($words[$k+$numWords])) {
// add the phrase to list of phrases
$phrases[] = implode( ,array_slice($words,$k,$numWords));
} // end if isset
} // end foreach $words
// create an array of phrases => count
$x = array_count_values($phrases);
// reverse sort it (preserving keys, since the keys are the phrases
arsort($x);
// if limit is specified, return only $limit phrases. otherwise, return all of them
return ($limit > 0) ? array_slice($x,0,$limit) : $x;
} // end getPhraseCount

//examples:

getPhraseCount($string); // return full list of single keyword count
getPhraseCount($string,2); // return full list of 2 word phrase count
getPhraseCount($string,2,10); // return top 10 list of 2 word phrase count

Description:
Okay, so basically this function will take the string and return a phrase => count  associative array.  If you only pass it the string, it defaults to doing a count of individual words and returning all of them in descending order.  Optional 2nd argument lets you specify how many words in the phrase.  So if you put 2 as 2nd argument, it will go through and for each word, take the word and the word after it and count how many times that 2 word phrase occurs, returning the list in descending order.  If the optional 3rd argument is used, it returns top x amount of words, so like 10 would return top 10 phrase occurance.

Limitations:

  • hyphenated words are not matched.
  • case in-sensitive.
  • assumes $string is "human" readable text.  In other words, if you were to pass a file_get_contents of some webpage to it, you should probably strip_tags() first, as well as do some regex to remove stuff between php script tags, etc...
If you enjoy reading this post then consider Subscribing to our blog in order to keep yourself updated with similar useful posts.

Monday, May 23, 2016

How to use jQuery Bootstrap DataTables with Example

Hello friends, today in this tutorial we will discuss about jQuery DataTables, Bootstrap a How-to tip, DataTables is a powerful jQuery plugin for creating dynamic tables which provides sorting, searching, records per page and pagination feature without any configuration. it's useful to create dynamic tables and you can use it in your projects, Before proceed please take a quick look of the live demo of jQuery DataTable, let's code
How to use jQuery Bootstrap DataTables with Example
Read more »