Tuesday, May 24, 2011

Transparent PHP proxy with GET, POST and HEADER support.

I needed to do cross-domain AJAX calls from a jQuery front-end to a PHP backend which was on another domain, and couldn't find a complete, functional example online... so I created my own. Since both servers had PHP (but the backend needed extra stuff that wasn't on the frontend server), doing a PHP Proxy was a great idea.


What this proxy supports:
  • GET and POST requests (POST was the whole reason for this, since jsonp doesn't support it!)
  • HTTP_REFERER check (only accept requests from one server)
  • COOKIES, in both directions (setting from the backend and sending from the frontend)
  • HEADERS, all of them, in both directions. This means it's a transparent proxy (yay!)
What it doesn't support (yet, maybe):
  • Dynamic destination (though that's relatively trivial to change), because I don't need it.
  • Load Balancing/Cycling, I may add this as a personal exercise in the future.
  • Authentication, beyond the referer check, or session (this should be handled by the backend anyway)
The Code

Because blogger.com sucks with code, the code is available directly on Google Code, at the following URL:
http://code.google.com/p/php-transparent-proxy/

Tuesday, May 10, 2011

The Forward Time Travel Paradox (FTTP)

Time to go into a little bit of metaphysical thinking here, thinking about paradoxes and time travel. If I'm going to post only once every blue moon, may as well make it an interesting one, don't you think?

So I am going to put forth a small hypothesis: If you were to travel into the future, the future you would travel to could not, ever, be the one that would happen when you get to it "the slow way". I shall call this hypothesis (or is it a theory? I don't know) The Forward Time Travel Paradox.


Every single science-fiction story that I've seen up to now that deals with time travel in a semi-logical way tries to cover the area of time paradoxes. They say, if you go into the past and kill your grandfather, or change anything that could make yourself not come into existence... Then you cause a paradox that destroys spacetime. But none - not a single one - talks about the paradox of travelling into the future. They all go "oh cool, the future, now we know what's going to happen, cool!" and go on with their story. Let's challenge the status quo.

The Premise

Let's say I invent a time machine that can go into the future. I want to test it for the first time (I know it works, I`ve done the calculations) so I simply hop in, set the dial for 100 years (so as to not run into my future self, obviously) and push the button. WHAM, I'm now in 2111.

If this happened to me, the first thing I would do would be to find any sort of data connection (probably some sort of wireless protocol with a TB/sec connection speed) and Google myself... And what would I find? Certainly not  front page news or a peer-reviewed paper on folding space into a wormhole to travel into the future... At best, some clipping on page 95B about my mysterious disappearance, and my last blog post before I left... My Gmail with a few million emails (and about a googabyte of free space!). What happened... to me? My life's work, gone? My hole existence, wiped out?

So I try to come back, expecting the worse... But nope, here I am back in the "present" and everything seems to go as planned! I publish my research paper, become famous, become known as the inventor of the Time Machine(tm). But one thing nags at me and becomes obvious each time someone visits the future, even by just a few days: It's never exactly the same when you actually get to it in "normal" time. There are always details that have changed!

The Explanation

The explanation is quite simple really; every time you hop on to the future, you're creating an alternate timeline in which you disappear and only re-appear at your destination. You travel 100 years into the future, it's a timeline where you were gone for that 100 years. But when you travel back, because you re-appeared before that 100 years, you've basically changed the future... You've just destroyed the timeline you created when you first went forward.

That would happen every time someone went forward into the future. All their possible children and descendants, every action they were to do, would temporarily go away until they come back even, if just for a millisecond. So what can be done about that? Absolutely nothing. Were we to actually figure out a way to go into the future, there would be no way of knowing whether or not the one we visit would be the one that would happen!

And, of course, an extra layer needs to be added to this basic truth, for any and all who still doubt. In the same way that visiting the past would change the present, visiting the future would also change it. If I were to visit a future where I could see the loto numbers, come back into the present and win a couple of million dollars... Then the future that I visited would no longer exist... Or rather, according to some theories, I would have created a new timeline where I won the lottery, a new branch in the eternal tree of spacetime, and I would follow this new path.

Conclusion

Time is fluid and ever changing. We may be part of a timeline where time travel will never be discovered, or it may be discovered today. Or, someone from the future may appear tomorrow and simply give us the technology just because they can, thus creating a new timeline where humanity starts using time travel in 2011 instead of 2273! Would we go back even further in time and give it to ourselves 100 years ago? Who knows... Once thing's for certain - when it comes to time travel, there is no such thing as a straight line and no such thing as just a visitor. As with Quantum Physics, the simple act of observing the future (or being observed in the past) changes the whole outcome of the experiment.

But then again, I don't understand Quantum Physics. If I were to understand quantum physics, I don't believe I would really understand it (or so the saying goes...).

Cheers for now, see you in an undetermined amount of time!