This is the other possibility, and the facts also fit this explanation. The assumption is that Doug starts dreaming during the procedure at Rekall, and everything that happens before that is reality. Doug simply has dreams about Mars, because he sees daily news footage of the guerrilla war going on there, and that's why he unconsciously incorporates it into his nightmares. Dreaming about an unknown woman may simply be coincidence; we all dream about anonymous people, she may simply be someone he once crossed on the street or met in a store, and not a recollection of an earlier memory. Or perhaps an subconscious clue that Doug is not so happy in his relation with Lori after all (as dreams are often highly metaphoric). A subtle clue that Doug's later adventure will be a dream might be that Bob, the salesman from Rekall, seems to be hesitant to let Doug make a virtual trip to Mars. Maybe because the daily news keeps showing how violent the situation on Mars is, and he fears that this knowledge may negatively affect Doug's dream. Which is exactly what happens with Doug and what causes his dream to run out of control. Aside from that, Bob tells him how the dream will go; Doug being a secret agent, people firing guns at him, the suite at the Hilton, and at the end killing the bad guy, rescuing the girl and saving Mars. Dr. Lull mentions alien machinery, and the Rekall technician comments that Doug's dream is called Blue Skies on Mars. And on top of that, Milena's face is already one of the options he has to choose from; all very conspicuous.
So the dream starts exactly when Doug is sedated in the chair at Rekall. The part where he wakes up, thinks he is Hauser and attacks the Rekall employees is the beginning of the dream. As Dr. Edgemar later confirms, Doug immediately had a schizoid embolism: his mind is reacting violently to the impant procedure; he is making the dream up as he goes, incorporating things and people he knows into the dream; this includes the procedure at Rekall, his wife Lori, Harry from work, Vilos Cohaagen, the Mars rebellion, and Milena from his dreams (although she could be an implant, as Doug chose her as his fantasy woman). People and things he doesn't know, like Richter and Benny, may be part of the original Ego Trip dream program. Due to the schizoid embolism however, Doug experiences extreme paranoia, thinking that he is a double agent whose memory has been erased, and who is hunted by almost everyone. Dr. Edgemar needs to intervene: he inserts a memory of himself in the dream and tries to convince Doug everything is the result of his imagination running wild; he even implants an image of Lori (the real one) to assure him. As happened in the Rekall office, Edgemar gives an outline of everything that is about to happen; saving the rebel cause, being Cohaagens bosom buddy, and the alien civilizations. Doug believes it for a minute, but then he sees Edgemar sweating. Now it can be speculated that Doug is so paranoid that he imagines the drop of sweat on Edgemar's head, practically giving himself a reason not to believe the doctor, and kill him. This is probably what Edgemar meant when he said that the "walls of reality" would come crashing down and Doug would be stuck in a permanent psychosis; Edgemar was Doug's only connection to reality, and by killing his only guide out, Doug ultimately rejects the real world and accepts the dream as reality, becoming permanently stuck inside an illusion. In this illusion, Lori immediately becomes a paranoid imagination again, attacking him and betraying him to Richter's men (the wall behind him even exploding, the walls literally crashing down around him). Doug plays out his dream, and in the end, the only way to get him back to the real world is by lobotomizing him, which is what happens when we see the flash of light.
Another distinct possibility (and probability) is that Doug had, in fact, visited Rekall once before, and that the movie itself follows his 2nd attempt at enjoying the Ego Trip, unbeknownst to him. Reason being, is that his memory of the 1st attempt was erased by Rekall as an illegal cover-up of their failure and nearly lobotomizing him. Hence Bob being very uneasy when Doug revisits Rekall and requests the Mars trip yet again. Bob puts on a smiley face and acts cool around Doug, maintaining his professional composure, so as to not tip Doug off that he's been there once already, especially considering what happened the previous time. So Bob tries to discourage Doug from Mars and coax him into trying out a different memory implant instead (so as to avoid the same outcome as last time). But of course, Doug doesn't budge. He wants Mars. After that, Bob thinks for a moment, and against his better judgement, reluctantly decides to accommodate Doug a 2nd time. Later, when Doug goes berserk, and is resedated, Bob states that he's just re-enacting the secret agent portion of his Ego Trip, and the doctor's rebuttal is they had not implanted it yet. Therefore, somewhere deep within Doug's subconscious, the original failed implant still existed. So, after failing twice now, they erase Doug's memory of ever going to Rekall and then create a mandatory policy on the spot that no one at Rekall has ever heard of him. This could also explain why Doug has been having vivid, reoccurring dreams of going to Mars and of Mileena before going back to Rekall: a residue of this first failed Ego Trip that Rekall did not manage to properly erase. That's why Mileena's face appears on the screen in front of Doug after he specifies what type of girl he wants in his fantasy, because she is in fact just a Rekall fabrication and he'd picked her the 1st time around, too. Guy knows what he wants. Doug's dream actually begins with his cab ride home, and not with him going beserk. The alien structures featured at the end of the movie also appear on the screen before Doug goes under. Hence them appearing within Doug's Ego Trip fantasy later on. The technician then mentions "Blue skies on Mars?" with a very cynical attitude in reference to a newly implemented feature to the Ego Trip storyline. Hence the fantasy ending with a blue sky on Mars. This theory is further supported by Doug's brief conversation about Rekall with his coworker/friend Harry at the quarry. Harry tells Doug not to go to Rekall and states that a "friend of his" went there and nearly got himself labotomized. Nearly. Harry is of course actually talking about Doug, (Harry knows Doug does not "recall" the 1st instance) and that's why when Doug disappointingly looks away from Harry and his advice, Harry looks back to Doug with a very worried expression. Worried that his friend will repeat the same mind threatening mistake. Which of course he does (or we wouldn't have a movie after all). Elements of his schizoid embolism are indeed self-implemented from Doug's reality. Such as his friend Harry & wife Lori being a part of it, suddenly trying to kill him. Doug also saw Cohaagan on the news many times before. So, just like a real dream functions, his delusion is a mixing pot of both real life figures and ones from the implant. The rest is just Doug's imagination running rampant as his true persona and made-up persona are at constant odds with one another, resulting in his eventual and inevitable labotomization, which ultimately transcends his reality. (Which we, in the real real world all know, is also made up.) Poor Doug. Should've listened to Harry. "Don't fuck with your brain, Pal. It ain't worth it."