You can't tell from online usually. It's why have to purchase from reputable reliable vendors. Someone selling knockoffs, counterfeit and fake products will usually use the OEM specifications and often use the original OEM photos.
I always read comments, reviews and most anything else about a seller/vendor to get an idea about what previous buyers had to say. I also look at the OEM website for a list of authorized dealers.
Of course there is the "gray market" as well. Vendors who import authentic phones but they are not authorized so they wont have the OEM Manufacturers warranty. Many of these sellers/shops offer an in-house warranty and will repair phones in their own shop. Just realize they won't stock parts so even if they are decent people you may wait weeks for repairs to be completed.
Most authorized dealers and repair shops will often just give you a replacement phone (usually remanufactured in pristine condition) or, if a simple repair, may have the parts in-stock.
So your best bet is either use an authorized dealer or research to find one of the reliable 3rd party sellers.
As the old adage (saying) goes "if it looks too good to be true, it probably isn't. If the price is well below what an authorized dealer or reputable shop, then it's likely it's not an original phone. You may have to save up a little longer to buy but in the long run its usually worth the extra money.
Finally, I often look at the OEMs who either sell directly or use one of the bigger retail or online websites (for example, Lazada selling Xiaomi smartphones. At least you are dealing with a seller with written guarantees and refund/return policies that (somewhat) protect the Buyer. The only alternative is to either buy the lowest cost phones that won't break your savings if they break quickly OR buy from one of the Mobile Carriers (Smart, Globe, etc)
Hope this helps. Good luck.