Studio Gri Fare Logo
-- epic emigration to Cyberland

List of Technologies   About Armagan Tekdoner

Ending the Stateless State — PHP

<?php $ip = $_SERVER["HTTP_CLIENT_IP"]; ?>

redefined Server-side Scripting in 1994.

"Something was here a second ago but it disappeared when I refreshed the page," you say?

The response is "No man ever steps in the same river twice, for it's not the same river and he's not the same man," as Heraclitus put.

CRUD Operations: Create - Read - Update - Delete

Once upon a time, there were webmasters around.

Today, any good user has the skills to qualify as a webmaster, therefore the webmaster title practically has been renamed as "admin". Actually, the vast majority of an admin's tasks fall into 4 main categories, as the title suggests. However, a working infrastructure is required for managing the content in the first place and constructing that infrastructure is the web developer's role.

Screenshot of an Admin Demo
Adminator Inc.

Test the admin side which enables those 4 crucial jobs and check its database-driven public pages that can be updated using this admin side.

Geolocation and More: No Permission Required

The moment we request a web page, the host website is capable of collecting lots of information about us. Our physical location is just one them. This website has absolutely no interest in collecting data about any of its visitors; this section only displays how it is possible to gather a hell lot of info, even without requiring one single click or any sort of consent.
Nothing you see here is stored.

Hello friend from Virginia Beach / US

PHP thinks that
Your IP is: 3.227.233.55
Your browser is: not detected
Your browser version is: 2.0

Validations

Web is full of forms and we fill a hell lot of them while doing almost any online job.

When a website needs real credentials to process a request, it should make sure that no one enters unwanted/invalid characters in fields.

All input fields are prone to hacker attacks that generally take the form of malicious code injections. Input fields should be protected by what is referred to as validations to prevent the users from entering unwanted codes. For example, a field for the individual's name does not need to house 10,000 characters or any numbers. Validators, thanks to regular expressions, allow only the pre-defined types of entries. (It is also very important to beware of poorly constructed regular expressions which validate out the real credentials.)

Here is an XHTML legacy form that can be customised by modifying plain text in the code files.

(The form above is being displayed in an iFrame, its original location is here. And its files that allow customisation have been made available here: DOWNLOAD)

Yet another server-side validations exercise that does the validation after form submittal. Perhaps slow; but unlike JavaScript, PHP validations cannot be disabled.

APIs: Servers Communicating with Servers

Many APIs certainly improve our lives.

However, I started to doubt whether creating original content still worths the effort, when John can easily display Bill's work on his page. Google has become the largest company on Earth only by displaying everything created on Earth, including the Earth itself; the only inventory the Facebook giant has, is made up of people who voluntarily make themselves its inventory; Amazon is the largest retailer with no stores; UBER has no taxis... This is hardly progress.

Anyway, here is an API for API's sake example: Google Blogger.

Name of the blog: Dummy Blog
Description of the blog: This is an experimentation blog.
Number of pages: 0
Number of posts: 3

Encoded and unformatted JSON data stored are:
{ "kind": "blogger#blog", "id": "405439155239204331", "name": "Dummy Blog", "description": "This is an experimentation blog.", "published": "2014-02-15T00:25:38-05:00", "updated": "2018-09-17T01:31:32-04:00", "url": "http://grifare.blogspot.com/", "selfLink": "https://www.googleapis.com/blogger/v3/blogs/405439155239204331", "posts": { "totalItems": 3, "selfLink": "https://www.googleapis.com/blogger/v3/blogs/405439155239204331/posts" }, "pages": { "totalItems": 0, "selfLink": "https://www.googleapis.com/blogger/v3/blogs/405439155239204331/pages" }, "locale": { "language": "en", "country": "GB", "variant": "" } }

The original location of the blog is at grifare.blogspot.ca

The PHP code below displays an external web page without using an iframe


// displays a page from ourbeautifulplanet.org with the owner's permission

  // fopen — Opens file or URL
  $externalURL = fopen("http://www.ourbeautifulplanet.org/space/facts-about-mars-life-on-the-red-planet/", "rb");
  /* 
   * stream_get_contents — Reads remainder of a stream into a string
   * string stream_get_contents ( resource $handle [, int $maxlength = -1 [, int $offset = -1 ]] )
   * Identical to file_get_contents(), except that stream_get_contents() operates on an already open stream resource
   * and returns the remaining contents in a string, up to maxlength bytes and starting at the specified offset.
   */
  $externalURLContents = stream_get_contents($externalURL);
	  
//// Converts relative paths to absolute, not needed in this case	  
//$fixPaths = array( '"//' => '"http://', "'//" => "'http://" );
//echo strtr( $externalURLContents, $fixPaths);

  print($externalURLContents);

Using the codes above, display someone else's web page as if it is a part of this domain.

The original location of the page is at facts-about-mars-life-on-the-red-planet

JS and PHP Collaboration: Enjoy the Puzzle

Screenshot of the puzzle exercise
The above-linked APP lets you upload an image and converts it into a puzzle.