Math is probably for you

November 22, 2009

Math can be really fun. Seriously.

This post is the 2nd in a series of posts I’m planning to have about why math is such a beautiful, useful, and awe-inspiring subject, and that a lot of us can do math (advanced/seemingly difficult math even). Math is such an integral part of humanity since our cave dwelling days, and much more so now in most of our technology driven lives. Previously I wrote about how even advanced math, particularly advanced geometry, can be easily tackled with just your imagination. This time it’s about probability. I can just imagine some of you cringe at the thought of math, let alone probability. But I’ll try to show you that often times, logical reasoning is all that it takes to wrap your head around probabilities, even the ones that confound a lot of brilliant people, even some mathematicians themselves. In fact, we’ll end this article with a simulation of a game/game show. Not bad huh? 🙂

Probability and people

In a nutshell, probability is the area of math which deals with the likelihood of an event happening. It is usually expressed as a number, whether a fraction or a decimal, between 0 and 1, with a probability of 1 meaning the event will surely happen and a probability of 0 meaning the event won’t happen.

Now, don’t be too hard on yourself thinking that probability is too hard for you, unlike most of the human population. In fact, probability is one really confounding area of math and problems in it that seem to be easy in hindsight, turn out to be deceptively difficult or tricky, even for  mathematicians, teachers, and other brilliant men and women around the globe. In fact a lot of us have trouble wrapping our heads around probabilities. You mix that with human hopefulness and also the difficulty of grasping very large numbers and what you get is the staggering number of people around the world falling in line to get their lotto tickets so they could win the multi-million prize money.

In fact, if we do the math, in a typical 6/49 game of lotto (6 unique numbers chosen out of 49 numbers, where the order of the 6 numbers is not important) we find that your chances of winning today after buying that lotto ticket is 1 in about 14,000,000. So if Lucy (one of the earliest hominids/proto-humans known to us) or her people, or perhaps even Neanderthals started betting on the lottery at the beginning of their lives, some of them should be millionaires by now. That’s how bad we are at assessing odds, especially coupled with large numbers. So when you go buy that lotto ticket later, I’m afraid the odds are so much against you.

However, I’ll discuss next a particularly perplexing probability problem pondered by people, even brilliant ones, and found the solution to be deceptively trivial after all. Actually, even after you get the explanation, from a practical standpoint it doesn’t seem like so. But the logical reasoning will quite surely buy you out. But don’t fret, all you need again is imagination and logical reasoning. 🙂

Game time

Some of you may have heard/read about the American game show Let’s Make a Deal. The Monty Hall problem (MHP) was named after the show’s host. Simply stated, the rules of the game are as follows:

The game master (GM), has 3 doors: 2 with goats behind them and one with a car behind it. The GM lets you choose one door, which you think holds the prize car behind it. Since the GM’s job is to make you and the audience excited and enjoy the game, the GM opens another door. But since the GM knows the placement of the goats and the car i.e. which door has which item behind it, the GM opens a door which has a goat behind it. Now, the GM poses a question to you: Do you or do you not want to change the door you initially picked i.e. the GM gives you an opportunity to stay with the door you originally picked, or to choose the other door, knowing that one of the doors, which the GM opened, has a goat behind it.

The GM in the show is of course Monty Hall (MH). Now, you’d most probably think that since there are only 2 doors left unopened, that the probability of getting either a goat or a car is now 50/50 or 50% right i.e. it doesn’t matter whether you switch doors or not?


In fact, however counterintuitive this may seem, your chances of getting the car at this point of the game doubles if you decide to change the door you initially picked. How? Let’s find out shall we? 🙂

Goat, Car, Goat

Now let’s strap on our imagination and logical reasoning caps to find out how the probability of getting the car increases two-fold if you switch your chosen door, and that it’s not a 50/50 chance of getting the car once a door with a goat has been opened by the GM.

Monty Hall problem

Monty Hall problem

One way of looking at how this counterintuitive probability problem is correctly tackled is by taking the possibility of the events one at a time (refer to the figure above please). In this scenario we show that when you switch doors, you always double your chances of winning. Here’s how:

1. First event, say you picked a door and it happened to have the prize car behind it.  Regardless of which door the GM opens, switching in this case either gives you goat A or goat B i.e. you lose the prize car. Out of the 3 possible scenarios (2 of which are listed right after this one), in this one event/case do you lose the prize car.

2. Second event, you choose a door with a goat (goat A) behind it. The GM opens a door again with a goat (goat B) behind it. If you switch in this case, you get the car. This event, wherein you get the car by switching, is one event which you get the prize car. Score one for you. 🙂

3. Third event, you choose the 3rd door with a goat(goat B) behind it. The GM again opens a door with a goat (this time, goat A). So when you switch, you get the car again. Yay. 🙂 This event, wherein you again get the car by switching, is another event which lets you take home the prize.

So what did we get from all this? We saw that out of 3 events/cases of picking either of the 3 doors, you always get 2 events (event 2. and 3.) which favor switching and which lets you walk away with the prize (or in this case, drive away with the prize). So the odds of getting the car/prize in the MHP is not 50% as a lot of us would initially assume, but instead, is really 2/3 or approximately 66.7%.

It can take a while to sink in, but the reasoning/explanation is quite logical and sound.

Try it out!

I actually tried this out with my mother and at another time with my younger brother. What I did was I got 3 opaque plastic cups (simulating the doors) and 2 toy cows (no goat toys in our house at that time) and 1 robot toy that transforms into a car (not bad for a prize no?). I made them act as a GM at one time, with me being the game contestant. Of course to prove my point I always switched. We did this about 20 times and I got the prize car (or robot) at around 14 times out of the 20 (roughly 2/3 of 20). Then I acted as a GM and they acted as the contestant. Then their job was not to switch doors (or cups), just to prove my point that you get the prize more often than not (2/3 of the time remember?) by switching instead of staying with your original door/cup.

They even asked me if I was doing a magic trick on them. I told them it was the power of mathematics and of logical thinking. 🙂 Imagine what much more primitive, let’s say Bronze-aged men, would think of me, with this knowledge, even without modern devices like a cellphone. Perhaps they’d think of me as an oracle or even a god. 🙂

Great, great. But what’s the use?

I think one important thing we can get from this (other than to show you that you can do maths you thought were too hard or complicated for you) is that with math, we can make decisions in our lives (sports betting, lottery, game shows and so on) with more clarity, logic, and sound reasoning, instead of just blind optimism.

If you didn’t get the logic on how to win the game at first glance, or if you thought it was 50/50, don’t be ashamed, a lot of people (some brilliant even) fell for it too. In fact, out of 228 subjects in a study, only 13% chose to switch, and that the rest (87%) assumed that the switching didn’t matter since the likelihood of getting the car out of the 2 unopened doors are equal (research by Mueser and Granberg, 1999).

Quoting cognitive psychologist Massimo Piattelli-Palmarini

“… no other statistical puzzle comes so close to fooling all the people all the time”


“that even Nobel physicists systematically give the wrong answer, and that they insist on it, and they are ready to berate in print those who propose the right answer.”

So, not bad eh? Still think math (or at least those areas you think are too advanced or complicated for you) isn’t for the average person? If so, then look forward to my next posts about math. 🙂

References, resources, and further reading

Holey Space

November 8, 2009

Nope that’s not a typo and this isn’t technically about religion. This post is about holes in space, namely black holes, wormholes, and the lesser known white holes, and their implications to the physical and metaphysical. The arrangement or flow of exposition of this article, from black to worm to white hole, will become much clearer as you read along the article. So get ready for a quick rundown on holes (cosmic ones of course), thought experiments, sci-fi love, paradoxes, and various possible implications in our lives and the universe we live in.

Read the rest of this entry »

Gather ’round kids, it’s time for math!

November 1, 2009

Mathematics is for everyone. Really.

This article ( and the succeeding ones in the series) aims to prove that point. That everyone has a mathematical brain. Specifically, I’ll concentrate on a certain area of mathematics in this article known as geometry, and then go to more advanced geometry (usually college or graduate level geometry). Don’t fret! There are no equations here which will make your eyes wander and do something else (at least while you’re reading the article). There are a lot of  science articles around, but what you usually don’t get often are articles about math, how beautiful and useful it is, and how important it is to science and modern civilization.

Read the rest of this entry »

Falling In Love: The Physics Of Attraction

October 12, 2009

This article discusses why the colloquial expressions such as “That’s why I gravitate towards you”, “I’m falling for you”, and “She is attracted to me” can be quite scientifically accurate. The following article muddles up the meanings of casual words like “falling” and “attraction” with the currently accepted theories, studies, and findings of physics on the related matters. I’ve done something like this before , similar in fashion to how the word “God” is poetically and figuratively used in relation to the “religious”  views of Einstein, Stephen Hawking, and other physicists . This time, it’s love. 🙂

First we have Space-Time

Space-time or spacetime is a mathematical model that you get when you combine the 3 dimensions of space with a 4th one,  the dimension of time.  In a nutshell, space-time is similar to a landscape where a point locates an event i.e. a 3 dimensional location + the time when it happened, instead of just a usual, spacial point in space like in maps, even if it’s a 3D map. Since space-time involves 4 dimensions, even most scientists find it very hard to imagine what 4 dimensions would look like, since us humans are accustomed to only 3 dimensions of our space. We always look at time as something that is fixed and unchanging. Newton certainly did when he wrote the laws of motion. One of the most impressive feats of Einstein was that he showed this was not so, and that time is as maleable as space.

To see this graphically, observe the image above. Since scientists are only humans, they have difficulties imagining warped 4 dimensions, and so 2 dimensional analogs are used, which are enough to illustrate the point. The image above shows a distortion in space-time.  These imaginations of space-time were first thought of as what are famously now known in science as thought experiments, with one of the most popular users being Albert Einstein himself.

Then there’s Gravity

General relativity describes gravity as a curvature in space-time and that, again in a nutshell,  gravity is a dent in space. To further picture this, consider again the image above. Ordinary matter, which makes up everything we see in the universe, causes space-time to warp and bend around it. The more matter there is in a given object or point, the more warping, denting,  and bending of space time, and therefore the stronger the gravity. The image shows the Earth, which is relatively quite massive, making a dent in the space-time continuum, thus creating a gravitational effect which pulls us, the moon, and other objects in space towards it, even including the Sun. The Sun of course has the strongest gravity or pull in the Solar system, since it’s the most massive object in it. Again, remember that the image is just a 2D analog of a 4D space-time continuum. The Earth does not immediately plummet towards the Sun since the Earth has its own gravity, which counteracts the Sun’s pull. But nevertheless the Earth is slowly circling down the drain/dent of the Sun in the space-time continuum (Sun’s gravity) and in a few billion years, the Earth and everything less massive than the Sun will quite likely plummet towards it. In other words, gravity is just an illusion since we can’t quite really conceive a 4th dimension in our minds, and that gravity is really just a warping of the space-time continuum.

You can then further imagine or create a thought experiment that other less or more massive bodies than the Earth in the Solar system create their own dents or warps in space-time. These include the other planets, asteroids, and even us humans, albeit in a very minute fraction only.

In fact, one of the suggested ways of mitigating a future asteroid impact on Earth is based on the premise that mass causes denting or warping in space-time. The gravity or gravitational tractor, as it is known, deflects an asteroid many years prior to its impact on Earth, by simply hovering or “parking” beside the asteroid. This form of asteroid mitigation does not really require cutting edge scientific discoveries or engineering feats, it does not need to physically contact the asteroid, and does not necessitate the need for the mechanical and structural composition of the asteroid in advance. Simply put, it works by allowing the relatively massive object, the gravity tractor, to “pull” the asteroid towards a direction which will lead it away from a future Earth impact. The “pull” comes from the fact that, slowly but surely, the tractor’s warping of space imposes a pull, albeit tiny, to the nearby asteroid.

Finally, Falling in Love

So, by now perhaps you’ve already surmised my coy and sly use of the words “falling” and “attraction” with respect to falling in love, as well as how physics currently views gravity and space-time. In other words, geeks and nerds like me often joke about how a girl could “fall” for you if you simply sit near her, since you do have mass, however minute. That mass of yours will eventually make her notice you, or perhaps not, but it will certainly impose a “pull” on her towards you, or vice versa. Of course technically speaking, it will take millions to billions of years before the more massive one between you two finally pulls the other. In this case, it’s better if you just ask her out, and that sometimes physicists, geeks, and nerds like me don’t really give that much good an advice. Still, as I mentioned earlier in this article, phrases such as “I’m falling for you” and “We’re attracted to each other” are quite scientifically accurate. Ah, love in geek or nerd speak. So romantic. 🙂

Which brings to mind the fascination of some men in today’s times to skinny women. Based from what I’ve pointed out here, it’s physically (by this I mean in physics) understandable why some men would prefer heavier or more massive women, but what about skinny women? I suppose the social sciences have more to learn and discuss in these matters. 🙂

Resources, references, and further reading:

Towards healthier skepticism: Correlation does not imply causation

October 9, 2009

This post will attempt to repeat, clarify, and elucidate the need for the remembrance and understanding of the phrase “correlation does not imply causation”. Scientific studies will be given, and the words in the phrase, which vary in meaning depending on usage, will be defined accordingly.

Scientific studies

Please take a moment to go through the following actual, summarized scientific research results:

1) In a previous scientific research using quantitative assessment, numerous epidemiological studies showed that women who were taking combined hormone replacement therapy (HRT) also had a lower-than-average incidence of coronary heart disease (CHD), leading doctors to propose that HRT was protective against CHD.

2) From a study at the University of Pennsylvania Medical Center, young children who sleep with the light on are much more likely to develop myopia in later life.

We will get back to them in a moment. Now we focus on correlation or co-relation, and why scientists, statisticians and skeptics, at the very least, should always maintain and promote the phrase “Correlation does not imply causation”.

Read the rest of this entry »

IPCop Linux, route command, and network routing

September 16, 2009

This short post is about the dilemma a coworker of mine just had this morning regarding network packets, and a not fully functional IPCop Linux installation.

The Dilemma

The server runs IPCop, which allows a PC to run as a firewall appliance. The IPCop server has 2 NICs, eth0 and eth1. Eth0 is connected to a Class A private LAN while eth1 uses a Class C address to connect to the public Internet. The problem however is that the Internet is accessible (Google, Yahoo! etc.) but not private LAN machines and addresses.  The private LAN’s gateway return ping replies, but not the DNS server.

Detective Work (i.e. Troubleshooting)

What I did was to check all possible causes for this problem: restart the network, checked logs for error messages and others, though some of these had already been done, but I just want to be doubly sure myself. I next checked the firewall using the iptables command. There were tens of lines of firewall rules, along with numerous chains. Since I was in a hurry at that time, I decided to skip the detailed checking of the firewall rules for the moment, even hough I have experience dealing directly with iptables, and not with the higher level application firewalls that just modify it. Next I tried to ping again the DNS server. Adding a -v in the ping command to make it more verbose, I noticed that packets were being successfully sent to the DNS server, but no packets were coming back. I thought to myself that the iptables firewall is one good suspect for this, but I’ll try a few more checks before I go to the nitty gritty of iptables firewall rules. I did ifconfig ethX up and then  down but to no avail. Replace the X with the NIC number you wish to up/down.

The Fix

I next checkd the routing table using the very useful route command. The static IP route looked fine, but I noticed that it was rathe incomplete, given that it has 2 NICs. What I mean by incomplete is that the route from the public, Class C network has routes for going in and out of the destination network and host, but the private LAN doesn’t have a route for traffic going into the IPCop server. It only has a route for traffic coming from the Class A private LAN NIC. Bingo was its name-o. 🙂 Apparently the reason why ping packets weren’t making their way back to the IPCop server was that they weren’t being routed correctly back to the IPCop server itself. This was further supported by using the traceroute command. I traceroute-ed the private LAN DNS server and as expected, the routing of the packet was all messed up. The traceroute packets for the private LAN DNS server were exiting through eth1, and out to the public Internet already. No wonder it doesn’t have a private LAN connection! 🙂

So the fix was to add a correct route to the routing table using the route command. The new route should, well, route the packets correctly from the  private LAN back to the IPCop server, and to make sure that the class A private LAN traffic enters/exits via the eth0 NIC. To do this the command

route add -net NETWORK netmask NETMASK gw GATEWAY

was used. Just replace NETWORK, NETMASK, and GATEWAY with the appropriate values for your network. In our case, NETWORK was the destination host ( the local machine, given by and GATEWAY was the gateway of the Class A network of the private LAN.

Sure enough, after adding that static route, the Class A private LAN became accessible. 🙂

route add -net netmask gw ipx4route add -net netmask gw ipx4

Estimating Distances Technique – A Detailed Inspection

September 14, 2009

This post is about a web article which mentions a technique that allows you to estimate, to a relatively good degree, your distance from another object. I’ll then explain the minor error which the article has, as well as the assumptions of the technique which the web article did not mention.

The Technique

I came across this neat trick from about estimating distances using your arm and thumb. It is quite useful, but below I will outline a relatively minor error of the article, particularly the diagram used. It was a minor error but it still strikes me as something that should be brought to light, since it’s pretty trivial too. The original article btw was taken from the article of the same name. Both articles were quite short so they only took me a small amount of time to read through them and to quickly notice that there was something wrong with the diagram.

The articles emphasize the fact that one’s arm (held straight) is approximately 10 times longer than the distance between your eyes. The articles also mention that with a bit of applied trigonometry, one can estimate distances between you and an object which you have a reliable width knowledge of. Unfortunately the article writer/s might have focused on the trigonometry part too much, overlooking their basic geometry when they created the diagram.

Here is the original diagram showing a man estimating his distance from a barn which he originally knows the approximate width.


How The Technique Works

In case you haven’t read the original article yet, it basically says that (again from

  • Hold one arm straight out in front of you, elbow straight, thumb pointing up.

  • Close one eye, and align one edge of your thumb with one edge of the barn.

  • Without moving your head or arm, switch eyes, now sighting with the eye that was closed and closing the other.

  • Your thumb will appear to jump sideways as a result of the change in perspective.

How far did it move? (Be sure to sight the same edge of your thumb when you switch eyes.)

  • Let’s say it jumped about five times the width of the barn, or about 500 feet.

  • Now multiply that figure by the handy constant 10 (the ratio of the length of your arm to the distance between your eyes).

Now you get the distance between you and the barn—5,000 feet, or about one mile. The accompanying diagram should make the whole process clear (shown above).

The Error In The Original Diagram

The error comes from the fact that the original diagram, whether it be the vertical one from or the horizontal, modified version from, show the distance line not being parallel to one line common to both triangles formed. To see this more clearly, I’ve created a little more technical and descriptive diagram below. The new diagram shows, correctly, that the distance line (containing the 5000′ and 20” distance markings) is parallel to the line connecting the observer’s left eye to the barn’s new location. That’s it. That’s the error 🙂 It may seem trivial, and it actually is, but I couldn’t help noticing it, especially since apparently no one has commented about it, and some people I know who should have noticed it, didn’t. 🙂 The original diagram shows the left-eye-new-barn-location line to be non-parallel to the distance line, which is wrong, and which quickly caught my skeptical eye. Basic geometry will tell you that my new diagram below is the more correct one.

wp-blog-post-estimating distances 2009-09-13

Assumptions Which Were Left Out

The assumptions which the article does not mention include:

  1. One knows a relatively precise measurement of the object’s width, or that one should know a good deal about the object’s width before attempting to estimate distance with this technique. To see how this can become a problem if not entirely taken into consideration, suppose you estimated or falsely remembered that the barn was 400ft instead of 500ft. That would translate to your estimated distance of 4000ft, which is 1000ft shorter than the correct 5000ft! 🙂 You’d then get a nasty surprise since you left out 1000ft. In other words, since the ratio of the object’s width to the distance between it and you is 10, your width estimation errors (again, could be from wrong estimation or remembrance of the object’s width) get translated to a distance error multiplied by 10.
  2. The topography of the terrain. This technique assumes or works best in a plain, since if you were say in a hilly or mountainous region, the distance you’ll get from this technique is the straight line distance from you to the object. But it does not take into consideration the slope, nor the crests or troughs of the land. You may get a distance of 1000ft between you and the object, but if there are hills and such between you and the object, you know it will be more than 1000ft. 🙂

Gracias a mis amigos Rudolf y Aaron. Thanks to my friends Rudolf and Aaron for their quick help in confirming this error, since I wanted to be triply sure. 🙂

My list of most attractive females in Star Trek TOS

September 5, 2009

The original Star Trek TV series simply known as, Star Trek The Original Series (TOS) and  which started airing in 1967, is one of the great backbones of sci-fi media in my opinion, whether it be film or television. The series was riddled with attempts (sometimes successful sometimes not so in my opinion) of profundity, and at times humor.  The themes of several episodes are recurring themes in succeeding sci-fi series and movies. The series though was conceived as a ‘serious’ primetime science fiction series, which I think means adopting or applying currently known scientific facts and researches at the time, instead of more often than not making things up without scientific temperament.

Here now is my list of the most physically attractive females (enemy or friend) in the whole 3 seasons of the series, in no particular order. Note that these are only the one-time female characters who are not part of the enterprise’ crew, as otherwise I would have included the lovely Nyota Uhura and other officers.

1. Nona from the second season episode of Star Trek The Original Series (TOS) entitled “A Private Little War“. She was played by actress Nancy Kovack. Interestingly enough, Nancy has quite a similar last name to a certain famous Watchmen character. 🙂  Unfortunately Nona became an antagonist and died for it. Still, she had a really beautiful face and a wonderful body 🙂

2. Eleen from the second season episode of Star Trek The Original Series (TOS) entitled “Friday’s Child“. Eleen was played by the beautiful Julie Newmar who is more famously known as one of 3 women who played Catwoman in the 1960s live action television series Batman. Eleen started as an antagonist though she decided to become otherwise at the end of the episode. Eleen was very beautiful, not to mention the way she pronounced Bones’ last name was really hot. 🙂 She pronounced it “Mac-coy” in a very sexy way 😉

3. Miramanee from the third season episode of Star Trek The Original Series (TOS) entitled  “The Paradise Syndrome“. Miramanee was a hot female Indian who seemingly became Pocahontas to Captain Kirk. In fact, she was so hot that Kirk had a child with her. Unfortunately, she died at the end of the episode 😦

4.Zarabeth from the third season episode of Star Trek The Original Series (TOS) entitled  “All Our Yesterdays”. Zarabeth was a lonely woman who was sent back in time to live in a cave amidst an ice age, since her planet at the time she came from was about to end. Thus she lived alone wearing only loin clothes. She had a very pretty face with a nice body. Thank you loin clothe 🙂

Comments in a ruly manner are most welcome 🙂

Default WordPress (Kubrick) stylesheet romantic poem :)

August 20, 2009

I was actually backing up my WordPress (WP) posts, tags, comments, etc. via the Export option in the Administration page when I stumbled into this poem. The backup was just in case I set up my own WP installation, say in my own domain. Nevertheless, I also tried downloading some pages of my blog that had images, particularly logos, which weren’t really stored in my WP blog but were instead taken from other sources in the web, via the HTML tag <img> and its parameter src.

Then came a surprising revelation: if you try using the current version of WP, Kubrick, and then you check the style sheet: you’ll be confronted with this nice, witty and funny poem (at least in my opinion) about a guy probably wanting to marry a girl:

/* “Daisy, Daisy, give me your answer do. I’m half crazy all for the love of you.
It won’t be a stylish marriage, I can’t afford a carriage.
But you’ll look sweet upon the seat of a bicycle built for two.” */

It’s at the bottom of the file style.css, which you can get by saving any page from a WP site using the Kubrick theme (and perhaps other themes made by Michael Heilemann, the maker of the Kubrick theme). You can actually see it for yourself by saving the page you are viewing now. Check the source code of the page you just saved (i.e. my web blog page) and then view the contents of style.css. Voila! The short poem above appears at the bottom, perhaps written by Michael Heilemann himself. 🙂

Of course this poem might be very famous and well-known already even though I’ve only found out about it just now. You’ll have to excuse my not so wide ‘circle’ of information sources. 🙂

I should try adding poetry sometime in the source codes of my software projects. Maybe I’ll do so now… 🙂

Fixing the PHP error/warning “Cannot modify header information – headers already sent “

August 18, 2009

This will be a quick post/note-to-self since I’m pretty occupied. Actually, the title of this post should have been “How to bloody fix the deceptively easy but hard to find confounding error in PHP headers: “warning Cannot modify header information – headers already sent”. But that’s too bloody long (though it would be interesting to find out in the future how WordPress concatenates long URLs…). The reason why I call it deceptive will be clarified at the 3rd entry below 🙂

The 2 primary parts of an HTTP request response are the headers and the body, which should be sent separately. Now in PHP sometimes some programmers, not just novice ones but long time ones (ehem…like me…) forget that we’re modifying them programmatically, which can sometimes cause errors. The header must always be sent first before the body, wherein both are coming from the web server. This is highlighted in this Wikipedia HTTP request example. For example, the php function header() can modify some of the (obviously) header parameters, most/all of which are listed in this Wikipedia list of HTTP headers. The above PHP error occurs because the body (or part of it) has already been sent by the server to the client, afterwhich a change of header values follows, either from the client or server.

Now, to finally fix the deceptively easy to fix but hard to find source of the error

Warning: Cannot modify header information – headers already sent by (<some of your PHP source files should be listed here>)

You can check the following:

1) If you’re using the header() function or some PHP function that modifies the header or controls the flow of action of your pages (e.g. from one page to another), you should inspect those. Usually it’s better to use conditional statements (e.g. IF or ELSE) to isolate the execution of one part of your code from another. It is quite likely that the error comes before or at the line of this function.

2) Make sure you don’t output/print/echo anything to the client (body) before sending/changing the headers. Again, conditional statements are useful here.

3) Finally, and the easiest to overlook, is to remove any white space outside the PHP start and end tags (<?php ?>). This is quite often the easiest thing to miss (for me at the least). The reason for this deceptive white space causing an error in PHP is that the white space is still interpreted as an echo statement printing a blank line, which interrupts the format of the HTTP header (see Wikipedia header format example above).

Of course the disclaimer here is that you are to most likely encounter this error if you’re more or less building your PHP application from the ground up, or without using web frameworks. It’s more unlikely and unusual to receive this error while you’re using an MVC based PHP framework.

warning Cannot modify header information – headers already sent But