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

Saturday, October 25, 2014

Detecting SSL in PHP on Heroku

In order to have a certified connection, websites would like to the user to use HTTPS instead of HTTP. However, sometimes we can't control what's the URL that the user request, which means that the user may ask for http://facebook.com instead of https://facebook.com.

So, to solve this problem, we detect that if the user is requesting HTTP URLs. And, if yes, response 301 to the user to ask him to redirect to our HTTPS site.

Normal, if we implement it in PHP, add the following code in the front of the file:


However, on Heroku, they don't have $_SERVER['HTTPS'] but $_SERVER['HTTP_X_FORWARDED_PROTO']) instead. So, we do:

Sunday, September 22, 2013

Upload File using jQuery-File-Upload

Original Code

https://github.com/blueimp/jQuery-File-Upload

My Work


This is cool jQuery library which allows the user to upload their files with cool interface. It also support "drag & drop", so it's much faster for people to select files. However, security may be a big issue in this case.

Problems I Met & How I Solved Them


Error, unable to upload the file

Solving this problem by giving right permission to the folder which the website is going to save files (in the example code, it's ./server/php/files). Make sure that "www-data" is able to "write" the folder.


The thumbnails are not showing up

I directly type in the URL of the thumbnails, and the browser showed a message asked me to read the error log file. In the log file, it says:
Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration, referer: http://heron.nctucs.net/upload/index.html
So, here my solution from this website:
ln -sf /etc/apache2/mods-available/headers.load /etc/apache2/mods-enabled/headers.load

Saturday, September 21, 2013

Internet.org

Original Document

Facts (sentences from the paper)

  • In its early days, Facebook ran on a single server that cost $85 a month and had to handle traffic for every Harvard student who used the service.
  • Facebook.com was first coded in PHP, which was perfect for the quick iterations that have since defined our style of product rollouts and release engineering.
  • Facebook has grown to 5,299 employees and 1.15 billion users as of June 2013.
  • Every day, there are more than 4.75 billion content items shared on Facebook, more than 4.5 billion "Likes," and more than 10 billion messages sent. More than 250 billion photos have been uploaded to Facebook, and more than 350 million photos are uploaded every day on average.
  • To build more efficient apps, Facebook is working to solve:
    • Diversity of devices and operating system
    • Geographic diversity
      • 1.15 billion people
      • 70 different languages
    • Network connectivity
      • Testing to ensure consistent network connectivity (Air Traffic Control to simulate different network conditions right inside Facebook' offices)
    • Consuming less data

Things

What I learned

Facebook.com was first complemented using PHP, what we all think it's easy and fast for developing. Then, they started to work very deep into PHP when more people using Facebook. This is new to me, what I thought is that this kind of websites doesn't go really deep into the technology but learning human psychology/business/etc insteads.


Sunday, June 30, 2013

Drupal Installation

Follow the instruction in Drupal tutorial:
https://drupal.org/documentation/install/settings-file

However, for the permission setting part, it's not working if I follow the instruction.
During the installation, Drupal may have to do some modifications on the files in sites/default/, they may be modified. So, 'w' is required.

The easiest way to solve the permission issue here is to grant all the permissions and modify them back as soon as the installation is done.

  • chmod 777 settings.php && chmod 777 ../default/
  • process the installation
  • chmod 644 settings.php ^&& chmod 755 ../default/
Done.