I'm assuming here that you're thinking of a 'free' or cost-sharing ride with a pilot, rather than actually hiring someone to fly you. In short, it may be possible but it depends on having a good relationship with the pilot and there could be some legal/regulatory issues (especially in the US, if that's where you are).
If you just want to fly as a passenger for the fun and experience, with no expectations at all about the route or duration of flight then the best thing you can do is to get involved in your local aviation community and make some contacts. I suspect that few pilots will take a complete stranger for a ride (see below for some US-centric reasons why not), but if you're a friend of a friend or a non-flying member of a flying club or whatever then that can open doors.
Of course, learning to fly would be an obvious way to get involved. If costs are a concern then you could consider gliding, which is significantly cheaper but would still let you make a lot of local aviation contacts. Or see if a local airport needs people to work on the line. Or maybe you have a complementary interest like photography and you can ask around at a local airport to see if any pilots would take you. But ultimately you'll have to establish a relationship of some kind with a pilot in order to go fly.
However, from the pilot's perspective there are some downsides to taking a 'random' stranger for a ride. First is simply trust and personal comfort level: do I want someone I don't know flying with me and (in most light aircraft) having access to the controls? Personally, I'd be concerned about possible panic attacks or simple motion sickness; someone trying to take over the aircraft is so unlikely that I think it's not worth worrying about.
Second - at least in the US, I don't know where you are - it's strictly forbidden for non-commercial pilots to receive any compensation for flying. "Compensation" is very broadly defined and even includes flying time itself, so if you want (or the pilots wants you) to contribute to the cost of the flights then it needs to be legal: the pilot must always pay at least his pro rata share. In most cases this isn't an issue because practically speaking the FAA has no way to know what private arrangements you've made and they certainly don't care if someone takes a friend for a flight and gets a free lunch in return. But there are limits: some companies are trying to create 'ride sharing' services to match pilots with passengers but the FAA has already said that it's illegal for private pilots to participate in them. Airpooler is the most prominent case, and their carefully worded FAQ saying that pilots are not compensated didn't persuade the FAA.
Finally there's liability: I know that many private pilots refuse to fly with passengers they don't know well because the risk of a lawsuit is so high in the case of an accident. I'm not saying that you personally would sue, but (in the worst case) your family or estate might.
So all in all, your best option is to get to know some pilots personally by whatever means works best for you given your location, interests and general access to aviation. I know that's a very vague answer, but a lot depends on your personal situation.