Generally, you cannot attack a player while they are online. However, if a player has attacked you before you came online, the results of the battle will be applied when the battle finishes.

Additionally, if you are in the Top 100 Global Leaderboard, it is possible for other players to revenge you while you are online.