<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kamal Mustafa on Medium]]></title>
        <description><![CDATA[Stories by Kamal Mustafa on Medium]]></description>
        <link>https://medium.com/@k4ml?source=rss-ecfe3f582feb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*iSqs2hYfKK2OhMK4.jpg</url>
            <title>Stories by Kamal Mustafa on Medium</title>
            <link>https://medium.com/@k4ml?source=rss-ecfe3f582feb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 13:14:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@k4ml/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[PHP: Headers already sent and HTTP basic]]></title>
            <link>https://medium.com/@k4ml/php-headers-already-sent-and-http-basic-6e04a36eb312?source=rss-ecfe3f582feb------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e04a36eb312</guid>
            <category><![CDATA[https]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Kamal Mustafa]]></dc:creator>
            <pubDate>Wed, 27 Apr 2016 03:06:35 GMT</pubDate>
            <atom:updated>2016-12-17T13:37:10.534Z</atom:updated>
            <content:encoded><![CDATA[<p>If there’s one error that must be encountered by all PHP developers, this:-</p><pre>Warning: Cannot modify header information - headers already sent by ...</pre><p>probably one of it. Anyone who developing in PHP must at least once having issue involving this. Lot of articles and answers have been written on this issue, and <a href="http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php">this answer on stackoverflow</a> is one of the most comprehensive write up explaining the issue, why it happen and how to fix it. So I don’t plan to talk much on the PHP part in this post but more on the HTTP part.</p><h3>What is HTTP ?</h3><p>It’s a protocol that govern how a piece of information can be exchanged over the Internet. There are lot of protocols defined and being used on the Internet but HTTP definitely one of the widely used protocol in form of what layman known as web, or World Wide Web (WWW). The protocol is being defined as <a href="https://www.ietf.org/rfc/rfc2616.txt">RFC 2616</a> and as we will later realized, it is a text protocol. Being a text based protocol make it much easier to study and understand and test it in practical manner since no special tools needed to actually implement the protocol. Before we delved deeper into the protocol, let also clear up what actually meant by the word protocol itself.</p><p>To put an analogy, when two human need to communicate with each other they both need to use some sort of language that both of them will understand. Someone who only know Malay and try to speak to another one that can only speak in English will definitely have some hard time understanding each other. While we human can actually sort that kind of problem with other means such as body language or facial expression, computers on the other hand are pretty dumb (or at least haven’t reach the human level of inteligence yet). So two computers that need to talk to each other, they must use some common language — thus the protocol. Please note however the protocol as being discussed here is more on high level protocol, or called as application layer. There are other protocol that involved moving the bits over the wire but we’re not going to discuss those.</p><p>As mentioned before, HTTP is a text protocol so when two computers (a client and a server) need to communicate they will just sent a bunch of text as outlined by the protocol. So a client may send the following to server:-</p><pre>GET /index.html HTTP/1.1</pre><p>Above is just a plain text that will be sent by client to a socket on the server, and the server on the other hand is required to return a response which also a plain text that may look like below:-</p><pre>HTTP/1.1 200 OK</pre><pre>Hello world</pre><p>I’d also mentioned above that we don’t need any special tools to actually implement this protocol. Any tools that can open a socket connection and let us send some text through it will do. So guess what tools that most computers already have ? The telnet. Let’s try to talk to a Google HTTP server and see what we’ll get:-</p><pre>$ telnet <a href="http://www.google.com/">www.google.com</a> 80 Trying 173.194.126.80...<br>Connected to <a href="http://www.google.com./">www.google.com.</a><br>Escape character is &#39;^]&#39;.<br>GET /index.html HTTP/1.1 HTTP/1.1 200 OK</pre><pre>Date: Mon, 03 Mar 2014 15:19:22 GMT<br>Expires: -1<br>Cache-Control: private, max-age=0<br>Content-Type: text/html; charset=ISO-8859-1<br>Set-Cookie: PREF=ID=9862b6886e93da12:FF=0:TM=1393859962:LM=1393859962:S=Vlib8XNFMPHru-3K; expires=Wed, 02-Mar-2016 15:19:22 GMT; path=/; domain=.google.com<br>Set-Cookie: NID=67=cC38fiwjW6qW5bcRzZuAAHmjY2qAwgPEM5m0QL3LuSoa_gtgzHgogLmZISsEovpLDRVLL4KcdhWXO-SmT6UJUfEJ3V6yn0xmp8XcLJfEFUJ92COvGcnxgi3oYHXZcguq; expires=Tue, 02-Sep-2014 15:19:22 GMT; path=/; domain=.google.com; HttpOnly<br>P3P: CP=&quot;This is not a P3P policy! See <a href="http://www.google.com/support/accounts/bin/answer.py?hl=en&amp;answer=151657">http://www.google.com/support/accounts/bin/answer.py?hl=en&amp;answer=151657</a> for more info.&quot;<br>Server: gws X-XSS-Protection: 1; mode=block<br>X-Frame-Options: SAMEORIGIN<br>Alternate-Protocol: 80:quic<br>Transfer-Encoding: chunked</pre><pre>8000<br>&lt;!doctype html&gt;&lt;html itemscope=&quot;&quot; itemtype=&quot;http://schema.org/WebPage&quot;&gt;&lt;head&gt;&lt;meta content=&quot;Search the world&#39;s information, including webpages, images, videos and more. Google has many special features to help you find exactly what you&#39;re looking for.&quot; name=&quot;description&quot;&gt;&lt;meta content=&quot;noodp&quot; name=&quot;robots&quot;&gt;&lt;meta itemprop=&quot;image&quot; content=&quot;/images/google_favicon_128.png&quot;&gt;&lt;title&gt;Google&lt;/title&gt;&lt;script&gt;(function(){ ...</pre><p>Ok, probably too much stuff for a starter ;)</p><h3>Request/Response format</h3><p>Basically the meat of HTTP is defining what is the format for a request and response. Both request and response basically using the same structure of content that is it is divided into 2 parts. The first part is called headers and the second part known as body.</p><pre>POST /index.html HTTP/1.1 ||<br>Host: <a href="http://www.google.com/">www.google.com</a>      ||&gt; headers<br>Accept: */*               ||</pre><pre>name=kamal&amp;address=jb ||&gt; body</pre><p>And the response:-</p><pre>HTTP/1.1 200 OK                             ||<br>Date: Mon, 03 Mar 2014 15:19:22 GMT         ||<br>Expires: -1                                 ||&gt; headers<br>Cache-Control: private, max-age=0           ||<br>Content-Type: text/html; charset=ISO-8859-1 ||</pre><pre>&lt;html&gt;&lt;head&gt;&lt;title&gt;...&lt;/html&gt;               ||&gt; body</pre><p>When using browsers to submit the HTTP request, the body part will probably what you’re typing in the forms and when receiving back the response, the body part usually what actually being rendered by browsers as the web page. For a normal users, the headers part usually not much a concern.</p><h3>PHP</h3><p>So what all above has any relation to the problem highlighted at the beginning of this post ? PHP (unfortunately) manage to hide (or in other word abstract out) all the low level details of the HTTP above through a simple language syntax. So to give an output from your PHP script, you just use the print or echo statement and PHP will do the job of ‘translating’ it into HTTP format. So, the PHP script:-</p><pre>&lt;?php print &#39;hello world&#39;;</pre><p>Might result in the following HTTP response:-</p><pre>HTTP/1.1 200 OK<br>Content-Type: text/html</pre><pre>hello world</pre><p>What if we need to include a custom header in the response ? We use the header() function:-</p><pre>&lt;?php header(&#39;Content-Type: text/plain&#39;);<br>print &#39;hello world&#39;;</pre><p>and it will be ‘translated’ as:-</p><pre>HTTP/1.1 200 OK<br>Content-Type: text/plain</pre><pre>hello world</pre><p>What if we call print first and later on header():-</p><pre>&lt;?php print &#39;hello world&#39;; header(&#39;Content-Type: text/plain&#39;)</pre><p>It will result in the following output:-</p><pre>HTTP/1.1 200 OK<br>hello world<br>Content-Type: text/plain</pre><p>And if you still following along this far, you’ll immediately noticed that the above output is wrong and this is the reason why PHP refuse to take it and giving you the infamous error Headers already sent ….</p><p><em>Originally published at </em><a href="http://k4ml.github.io/posts/php-headers-already-sent-and-http-basic.html"><em>k4ml.github.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e04a36eb312" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[You can’t teach student English]]></title>
            <link>https://medium.com/@k4ml/you-cant-teach-student-english-98625cf9cbf6?source=rss-ecfe3f582feb------2</link>
            <guid isPermaLink="false">https://medium.com/p/98625cf9cbf6</guid>
            <category><![CDATA[english-learning]]></category>
            <category><![CDATA[education]]></category>
            <dc:creator><![CDATA[Kamal Mustafa]]></dc:creator>
            <pubDate>Tue, 26 Apr 2016 15:40:15 GMT</pubDate>
            <atom:updated>2016-04-26T15:40:15.427Z</atom:updated>
            <content:encoded><![CDATA[<p>6 years in primary school, 5 years in secondary school. That’s how much student learnt the English language in their school years in Malaysia. Yet, the subject of English proficiency comes so often in the local media.</p><p>I’m not talking about others — me myself barely can read English books or newspapers when I came out of secondary school. Let alone to speak or converse in the language.</p><p>But when I took my IT course at university, the medium of learning is all in English. For the first time in my life, I have to write in English, answering exam paper, not in an English class. It is a whole new experience to me.</p><p>Now one might be quick to say — that’s why you need to enforce English based medium in school. In Malaysia, we call(ed) that PPSMI — Pengajaran dan Pembelajaran Sains dan Matematik dalam Bahasa Inggeris (<em>the teaching and learning of science and mathematics in English). </em>It’s a hot debate and now the policy has been scrapped out.</p><p>But I beg to differ. It’s not the medium that forced me to take on English. If that the case then the 80% others who took IT course with me would now a software developer, sysadmin, IT manager or whatever job in computer industry, or at least computer related. Instead, they dumped the course, just making sure they can in ‘some way’ got their degree out.</p><p>What took me into learning English is my passion and interest in computer and programming. I love to read all those articles on programming language, how you build using these and that technology. So I need to master English.</p><p>So you can’t teach student English. The 11 years English class in school is an evident. But you can make them to love computer, painting, automative, telecommunication etc, and if that require them to master English — they will.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98625cf9cbf6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What it mean by being explicit in Python ?]]></title>
            <link>https://medium.com/@k4ml/what-it-mean-by-being-explicit-in-python-9cbfa3a8a198?source=rss-ecfe3f582feb------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cbfa3a8a198</guid>
            <dc:creator><![CDATA[Kamal Mustafa]]></dc:creator>
            <pubDate>Sun, 15 Feb 2015 13:27:09 GMT</pubDate>
            <atom:updated>2015-11-15T07:58:07.419Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re just looking into Python, you’d probably have heard that people are talking one of the plus points (or minus) of the language is how explicit it is.</p><p>Parts of the Zen of Python basically goes like this:-</p><blockquote>Beautiful is better than ugly.<br>Explicit is better than implicit.<br>Simple is better than complex.<br>Complex is better than complicated.<br>Flat is better than nested.<br>Sparse is better than dense.<br>Readability counts.</blockquote><p>You can read more by typing <em>import this</em> in the Python console. Without explaining too much, let me show via an example. Take the following snippet from Rails’s model definition:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*4AlhWInWCiAM07eGyJkOCQ.png" /></figure><p>Now the same code, if it were to be written in Python will be like this:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*7eR3Z-zmyO_fbEcrt2214w.png" /></figure><p>We can see that the Python version has almost all the information that we need in order to trace the code execution. The Rails snippet on the other hand will leave you with the following question:-</p><p>What is AppConfig ? Where it came from ?</p><p>What is HTTParty ? Where it came from ?</p><p>What exactly being returned by each method ?</p><p>The Rails snippet require you to know how the underlying environment of the code work. If you’re just jumping into this piece of code for some quick debugging or fix, and you don’t know much of Rails yet, it will be very frustrating moment.</p><h3>Disclaimers</h3><p>The writing on this site are my own and don’t necessarily represent my employer’s positions, strategies or opinions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cbfa3a8a198" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>