To add several points, if you are being attacked, normally, not being phalanxed, don't get mad at them, or start flaming, or pleading. Simply send a message to them saying that you are indeed online, and politely ask them to withdraw their fleet. This usually will work. If you start flaming them, they're certainly not going to withdraw their fleet, and they are likely to continue attacking you, just to spite you.
Now as phalanx goes, if there is someone who has espionaged you while your fleet is on your planet at one time or another, and they have a moon and continue to espionage that planet, or you are continually phalanxed by someone, don't just give up building fleets. If you really want a fleet, build the fleet and then send it to another planet in your system for safekeeping. There isn't much you can do if a phalanx fleet is sent out against your returning fleet.
For those of you who don't know, a phalanx is something that can be built on a moon, and it can be used on a planet to allow the person using the phalanx to be able to see all fleets leaving or coming to the planet. It's a very useful tool for offense.