ad

Monday, 26 October 2015

PHP snippet | Format POST Array

I wrote this little functions to dumb your POST array data into a nice little table. Post associate array can be a little confusing for someone who is just starting out, if ya wanna check your submitted data in formatted table call the function dump_data();

Before:


After:



https://github.com/phpdevsami/Show-post-data-in-a-clean-table

Saturday, 24 October 2015

PHP Script | Store all $_SERVER variable data into database and retrieve


This script will stores all the data that resides in $_SERVER variable into one field in databse which can be retrived as a regular array


How to use:
To use this object instantiate the Server class and pass the required parameters. Required parameters are: ($database_object, $table_name, $field_name). This object offers two method, one to save data to databse, another to retrived saved data.

Requred variables: 
  • $id variable takes the column you are selecting.  
  • $datbase_object takes the databse object that is from database connection.
  • $table_name takes the name of the table that you want to select data from.  
  • $field_name if the name of the field in table where the server information will be or is stored 

Methods:
  • save_data() method will return true or false if data fails to insert into server, like $_Server->save_data();
  • get_data() method will return the exact array that was saved in database, from where you can either loop through it or get each value using its key like, $Server->get_data()['HTTP_HOST'] This method requires and arguement $id 

Storage:
storing server variable in database


 
Retrieval:
php array unserialized






https://github.com/phpdevsami/Store-SERVER-array-into-database
https://dl.dropboxusercontent.com/u/28490184/webdevtown/store%20server%20into%20db.rar

Friday, 16 October 2015

Sending POST requests with AJAX for absolute beginners

First things frst, what is AJAX?
AJAX is a client side script that communicates with server without the need to refresh the web page - in other words it works asynchronously.

Why'd I need AJAX anyways?
What about when you wanna get data from server and put it into a dable without refresh? What about when you wanna check whether username alrady exists without refresh?

How do I send a GET request with AJAX?
Use get method, and a callback function inside that takes two parameters, first returns the page, second the sucess or failed result.
To test our script out, lets create two pages, index.html and data.php, we'll send GET request to data.php from index.html page, and echo whatever is returned. I'd write something in index.php file so I can see whatever has returned.

        $.get("data.php", function(data, text){
            document.write(data);
        } );


Run the above code inside <scirpt> tags and you should see whatever was in the index.php file. That's our basic GET request done.

Q. I'm trying to load a website but it returns 301 page moved permanently?
A. The website has been moved to different URL. Read my HTTP the very basics tutorial to learn more about HTTP and headers. If website has been moved to different URL, it should generally send a Location header to your client. Try that URL.


How do I send POST request to a page?
To send a POST request use the following, pretty much same syntax as GET method but we'll add some POST data, like username and password. Basically we're going to send username and password to data.php page which has following code. Usually you'd get validate POST data and tyr matching it against user and password in SQL DB:
    if( ($_POST["username"] == "cloudcomputing") and ($_POST["password"] == "jquery") ){
        echo "Correct username and password";
    }else{
        echo "Wrong username or password";
    }


Lets send it some data from index.html page. By the way, you can read more about this method here
http://api.jquery.com/jquery.post/

Lets send username and password.
        $.post("data.php", {
            username: "loudcomputing",
            password: "jquery"
        }, function(data, result){
            document.write(data);
        });     
   

Guess what is returns? Wrong username or password. Change sending password to cloudcomputing and it'll grant the access.

So that's pretty much to it, sending basic GET or POST request is where you start and and when you're familiar with it you start adding little things to secure it.. from there on it's all trial and error and basic knowledge of how HTTP protocol works.

Wednesday, 14 October 2015

Can you really learn programming on your own?

The short answer is, yes. Now the long answer..

when most people talk about programming they have this complex algorithm, thousands of lines of code, weird looking flocharts in mind, and more often than not this raises a questions whether such complex subject is even possible to master without attending college, taking computer science program or being taught from some guru

I get dozens of questions from people asking how to learn programming? what's the best resource to learn programming? and so on.. I ask these guys, why would you like to learn programming? they say, I want to build website, then I ask, what website?, I get a response something along the lines that they want to be able to build any website. Right there I know even if these people started programming right now and came back after 5 years, they would still be wondering around, learning random things from random videos, making random small programs.

Now here is another guy. He wants to build a page to collect email addresses for marketing purpose. Right there half of his learning is done.. this guy is far more likely to understand and learn programming than the other dude who is still lost.. not to mention both of these are amateurs, except one has a vision of what he wants to do, is well aware of his ultimate goal, while other guy is looking for something that may along the way define his ultimate goal.

Another, difference between this guy and the previous guy is, this guy right here will not bother clicking on links like Can you really learn programming on your own? he knows what exactly he wants, all he needs is a path to get there. Instead the question he may ask is, how to build this.

To answer the title of this post Can you really learn programming on your own? I will raise a counter question, what is it exactly that you would like to build after you know programming? when you have answered this question, half of your puzzle will be solved, and to solve another half, I am going to link you to this guy.

Now lets do a little time travelling.. theory or techniques you may have missed from not taking CS course, will come and block your way down the road and force you to learn. It does not really matter whether you learn them now or later on, fact of the matter is, as you get better and better, you will be forced to learn it all, your goals will make you do it, now it will become your own choice whether you want to be taught or you can figure things out to acomlpish your goals yourself.

Sunday, 11 October 2015

How to verify data integrity using MD5 cryptographic algorithm

What is MD5 you ask? 

MD5 stands for message digest 5. It's an algorithm used to create data digest to verify it's integrity. Just like every human being has unique fingerprint, every file that goes through this algorithm brings a fixed length hash, this hash cannot be reversed.

What's the use of MD5?

MD5 is most commonly used to hash user password and data verification. When user signs up to a website his password is hashed, and stored in the database, when user tries to login, his password is again hashed and matched against the hash stored in database. So even if his website database is compromised, hacker wouldn't be able to see the passwords, thought this doesn't mean your data is completely secure, more often than not users use common passwords like 123456, 00000 etc.. hacker would simple use a dictinary of common known hashes to crack down your password, so it's very important that your suggest user to choose as strong password as possible.

How does data verification work with MD5?

Data verification or data integrity check work by creating a digest or hash of a certain application/file, every digest generated by MD5 is unique. For example, lets say you've made a file avilable for download, how would the users know whether someone who's linking to a mirrored download is a genuine file and not some virus attached to original file? Well that's where MD5 comes into play, you can compute an hash of your application and post it on your website, now whenever someone downloads it from your or someone else's website he would use a utility like Microsoft file checksum integrity verifier to compute a hash for either MD5 or SHA1, and compare it against the hash that was provided on your original website, if the hash is same, the file's exact as the original one, else, something in that file has been modified.

Friday, 25 September 2015

What's a Proxy server and how it works for absolute beginners

Figured I'd write a little article on this since there's so many people that seem to be working with proxies without really knowing what it really is and how it works.
-

First things first, for those who don't know what a proxy is, it's a computer, to be more specific, it's a computer running apache or other server software, and those who don't know what apache is, it's a piece of software that runs on a computer which allows a client software to request data from your server using URL. Client software is your web browser. We generally call is 2 tier architecture, this is, client(browser) taking care of presentation and client side data manipulation, and server doing it's job behind the scene in the computer running apache software.

I won't talk about DNS server, but essencially whenever you type URL in address bar and press enter, that URL is translated into IP address AKA dotted squad - DNS does this, it's where the www.example.com address is matched with associated with IP. Then this IP is sent back to your browser and browser then sends requests to it and waits for response back from apache server.

Client server model(picture from pecktechdesigns.com):
[​IMG]

So here we've clients making requests to the server, using HTTP(read more about this protocol here).

Alright so far so good. We've client, it has a regular IP, and we've a server which also has an IP, right. But what if we want to change client's IP. That is where proxy server comes in, you take a server place it between client and server.

So this is how it looks like(picture from forrester-infosystems.wikispaces.com):
[​IMG]
Internet = A computer running apache software.
Server = Web server where you're making requests, server where files or webpage are located.


As you see here, left side computers are clients, middle one is a our new server, and Internet(right side one) is our web server. So whenever the client makes a request for anything from Internet, it goes through the Proxy Server. Proxy server is a new server that's been placed between client and Internet so whatever you do, will go through it. For instance, if you try to visit a website and it's blocked, you should know it was the Proxy Server that dected something in your request. Or look at this one, someone's trying to hack your computer, he wont just be able to go and attack your computer directly, he'll have to go through proxy server. Or check this one out, you're on a little local network that uses proxy server, your server administrator could configure your Proxy Server to cache webpages.. so whoever after you tries to visit the same webapage, will get it without the need to download it again.

Okay so if you're still reading, then keep reading before it's about to get interesting here. When you tell your browser to connect to certain proxy server, lets say you're connected to 1.1.1.1.1.1 server, which's a proxy server, what this server will do is send your request to the server you're requesting data from, while at it, it will hide your IP address and give the requesting server it's own IP address(1.1.1.1.1.1). So basically if your address is 2.2.2.2.2.2, it's giving the server 1.1.1.1.1.1.1.

Check this picture out, we've a Proxy Server located in US which has US IP so whenever you're making request to webpage using that server, that seerver will request the data for you, not letting the web server about your IP. Example, lets say you're making bunch of spammy comments on thebot.net money making website, trying to promote your new blog.. you've been doing this or a day and the administrator has finally noticed it. Now administrator goes to his log file and looks up IP address associated with your account. He wont see your IP address, he'll see this proxy server's address. Lets say he finally decided to block this Proxy Server. What can you do now is simple switch your Proxy Server and you're live again.
Picture from(anfieldroad.com):
[​IMG]

Still reading? Lets make it a even more tricky here. What if you wanted to hide behind multiple Proxy servers? There's a way to do it, there's plenty of sevices that offer hops, it's basically connecting to A proxy server, which's connected to B, which to C and then C finally to your destination server. Making it even more complex to track the source of client/request back.

But remember like I said in the beginning, Proxy server is just a computer. So when you request data from www.example.com through Proxy Server, the Proxy server is sending request to Server, requesting data for you, then uploading that data to your computer. Which mean, faster Proxy Server's internet connection. The faster the process will happen.

Sunday, 6 September 2015

Free e-commerce website | Paypal Payment Options


Completely free of charge ecommerce script | No no hidden costs | Under GNU/GPL license.

This is a small e-commerce website that allows you to sell up-to 4 products. It comes with Admin Panel where you're allowed to Add or Remove Product. Admin Panel also allows you to set the receiver Paypal along with site template information like site title, header, footer logo etc..

IMPORTANT: Just after editing the database information in conn.php file and connecting to database, and importing SQL files your first priority should be to open admin table and edit the user and password. Md5 hash your password when you paste it in password field in database. To md5 just search on google for md5 hash generator and generate your password using it. Then when loggin in, just use regular password.

Rest of it is easy. Once you're in Admin Panel, you'll see three buttons, Add Product, Delete product and Add Site Info. To add a product just click on Add Product button, fill all the details and press enter.
Note that it wont allow you to add any more products than 4. If 4 products are already in database you'll be asked to delete atleast one product.

The Add Site Info button will also allow you to add your Paypal.

And to use the Delete Product option just click the button and you'll be presented with links of your product. To delete a product, just click on it and it'll be deleted.

Make sure atlease 4 products are available on website, or a message will appear asking you to add the missing product.

Also make sure required bootstrap files are not deleted, this site uses bootstrap for document styling and structure.

Lastly, use the script at your own risk.

Script developed by | - samiuddin | phpdevsami@gmail.com | http://wwww.webdevtown.com | https://github.com/phpdevsami

Download
https://dl.dropboxusercontent.com/u/28490184/webdevtown/ecommerce_site.rar

Screenshorts