Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Thursday, February 5, 2009

Really cheap webhosting?

If you ever wanted to have unlimited websites managed all from one place, instead of paying for extremely limited access to hosting servers which are insecure, and expensive?

I got myself my first VPS a few days ago from http://www.vpsvillage.com. It costs me only 6$/mo and I get to put there as many websites I want (well, it's my server, that's the point of it). Not only that, but a VPS is much more secure than shared webhosting. If a hacker takes over a shared hosting server from any webpage, he could easily take over your files and read your source code from the websites (which could often contain passwords and other secret information). It's not that it's impossible to take over a VPS hosting server, it's just much more difficult to do even if a hacker succeeds on taking over one of the VPS servers.

Of course there's a catch - you have to learn how to be your own webhosting IT manager. I admit - it's not an easy task, but once you learn how to do it, having full control over your website is a huge benefit.

I would suggest using Debian for a start, and reading some HOWTO's on howtoforge.com. For example, to set up a LAMP server (Linux/Apache/MySQL/PHP), what you should do is follow simple instructions from here - http://www.howtoforge.com/ubuntu_debian_lamp_server. Setting up unlimited (duuuh) mailboxes and mail forwarding is easily done using postfix, and you can even set up your own DNS server on the VPS, so adding domains to your VPS is also very easy.

Monday, April 23, 2007

Cheating on Bandwidth with PHP

Note: I am NOT responsible for anything that could happen if you actually try this (especially if your web hosting service decides to sue you).

PHP is a very fun scripting language. Besides the stanard behaviour that is expected from an honest script to connect to a database, parse the information and display it to the user, PHP can do a few tricks as well. One of them, is to create a listening socket and forking a new process.

If your web hosting allows you to fork and create a listening socket through PHP, you might just be able to do some nasty things so that your visitors will download content from another port on the server, instead of through the Apache web server. Traffic that is being downloaded from your site through Apache gets summed up and limited, usually for a fixed amount per month, depending on your hosting package. If you decide to get more bandwidth, you need to pay more.

But what if you could get your site's visitors to download the content itself from a forked process from PHP that listens to a specific port and acts like a web server? The user will manage to downlaod content from your site, and the bandwidth will not be accounted for.

The algorithm:
  1. Use mod_rewrite on specific directories to send the requested file name to send through a PHP script
  2. The PHP script will either create the download link or send a Redirect header in the following manner: http://www.yoursite.com:[random_port], while random_port is a number between 1024 and 65535 (Ports below 1024 are privileged ports).
  3. At the same time that the link is created, use fork to create a small temporary daemon that will run in the background and wait for a connection.
  4. The client will attempt to download the file through the chosen port.
  5. The forked PHP script will parse the HTTP request and send the requested file back to the client. The HTTP request will be a very simple one (something like "GET / HTTP/1.1" and a few more insignificant headers) since we already know exactly which file to send. (One of the parameters to our script was the file name).
  6. It is possible to leave the forked daemon on, but that would really be nasty :)

Probably the most obvieous reason why this won't work usually is because of PHP security settings that will not allow you to do this hack. Other than that, most servers today have firewalls for incoming connections, especially on unprivileged ports. If your server's hosting is lame enough, you might actually succeed in doing this.