This stopped after the World Trade Center attacks.
You might be able to get a kid in briefly before the plane takes off.
aviation.stackexchange.com/users/1378/Tyler Durden
Generally speaking, you will not get very lucky unless you are a pilot yourself and are carrying your license with you (and even then, this is airline dependent).
If this is the case, you might even be able to ride in the jump seat for a portion of the flight
On the ground a lot of pilots/cabin crew are friendly and would be happy to show you around.
Use common sense though and ask to go after landing for the best chance - before take off the crew will be quite busy with pre-flight checks.
aviation.stackexchange.com/users/7409/mccdyl001
Usually the cockpit is restricted during any phase of flight besides boarding/de boarding.
This is usually the case with major airlines with any destination in Europe, or the U.S., not sure abut Asia though
aviation.stackexchange.com/users/7373/woakley5
Can I ask to go to the cockpit during a flight ?
Of course you can.
The answer will be a firm "No" and you will be watched very closely by the cabin crew and any plainclothes security onboard until you land.
It's possible the police will be waiting for you.
Can I ask to go to the cockpit after a flight ?
Of course you can.
If it's a longer stop the crew are often happy to show off their office.
If it's the end of a 12 hour intercontinental flight with a bad-weather landing they might decline.
aviation.stackexchange.com/users/2590/paul
It's a security and/or safety risk to allow any persons in the cockpit these days.
This accident happened as a pilot allowed his children to take control during flight.
With the autopilot active, Kudrinsky, against regulations, let the children sit at the controls.
I've seen flight crashes, in which persons in the cockpit have interfered with the flight in one way or the other.
Based on these experiences, unauthorized persons in the cockpit is totally not allowed these days.
aviation.stackexchange.com/users/7407/KhoPhi
About 30 years ago I did this during flight when I was a kid.
These days I manage to do it for my daughter but only while boarding.
aviation.stackexchange.com/users/100/Jamiec
As a kid, I remember going to the cockpit of a plane with my mom (I believe the airline was  AOM French Airlines ).  Is this still possible now?  I understand the answer might differ with different airlines/countries, I'm mostly interested in European and Asian airlines/countries, specifically Japanese.  Is there some specific regulations for international flights, or does it depends on departure/arrival locations?
Can a passenger request to visit the cockpit during a flight?
aviation.stackexchange.com
<safety><commercial-aviation><pilots><cockpit><regulations>
aviation.stackexchange.com/questions/12863
aviation.stackexchange.com/users/4105/Antzi
Allowing passenegs in the cockpit was stopped after the Wordl Trade Center attacks. Allowing anyone in the cockpit is a security risk, even licenced pilots may or may not be allowed depending on the airline. It may be possible while the plane is on the ground. There have been crashes caused by people in the cockpit. The main issue here is safety and security. Access to the cockpit is restricted during flights except for boarding and disembarking. The practice of letting people into the cockpit stopped after the World Trade Center attacks. There have been instances of flights crashing as a result of people interfering with the flight while in the cockpit. 

When the plane is on the ground, the pilots/crew may be happy to show you around. A child may be able to enter the cockpit briefly before take-off. Most of the time, you are unlikely to be allowed into the cockpit unless you are a pilot carrying your license.
The main issue here is safety and security. Access to the cockpit is restricted during flights except for boarding and disembarking. The practice of letting people into the cockpit stopped after the World Trade Center attacks.   When the plane is on the ground, the pilots/crew may be happy to show you around. A child may be able to enter the cockpit briefly before take-off. Most of the time, you are unlikely to be allowed into the cockpit unless you are a pilot carrying your license. There have been instances of flights crashing as a result of people interfering with the flight while in the cockpit.