Can I do it on purpose? Can I do it with a real camera?
Yes, and yes. People usually try to avoid that effect, called lens flare, but sometimes it adds an interesting creative element. You should never point your camera directly at the sun, but if you frame a shot so that the sun is out of the frame but nearby there's a good chance you'll get some flare. Removing the hood from your lens will improve your chances of lens flare since the point of the hood is to block light from the side that usually causes flare. Other light sources, like streetlights, can also cause flare. Different lenses and different light sources give different kinds of flare, so experiment. (And again, don't point your camera at the sun.)