According to the Bible how does one receive the gift of the Holy Ghost? Does one automatically receive the Holy Ghost after they accept Christ or does it have to be received through the laying on of hands as spoken of in Acts 8?

Acts 8:14 Now when the apostles which were at Jerusalem heard that Samaria had received the word of God, they sent unto them Peter and John:
15 Who, when they were come down, prayed for them, that they might receive the Holy Ghost:
16 (For as yet he was fallen upon none of them: only they were baptized in the name of the Lord Jesus.)
17 Then laid they their hands on them, and they received the Holy Ghost.
Acts 8:15 actually provides the answer: 


  “Who, when they (Peter &amp; John) were come down, prayed for them, that they might receive the Holy Ghost”


Prayer is the key ingredient that enabled the reception of the Holy Spirit, however, there is more to the story, because there was one there that believed that the laying on of hands was the agent of release of the Holy Spirit rather than prayer and his name was Simon beginning in verse 9 lets focus on Simon and ultimately Peter’s response:


  But there was a certain man, called Simon, which beforetime in the same city used sorcery, and bewitched the people of Samaria, giving out that himself was some great one: To whom they all gave heed, from the least to the greatest, saying, This man is the great power of God. And to him they had regard, because that of long time he had bewitched them with sorceries... Then Simon himself believed also: and when he was baptized, he continued with Philip, and wondered, beholding the miracles and signs which were done… And when Simon saw that through laying on of the apostles' hands the Holy Ghost was given, he offered them money, Saying, Give me also this power, that on whomsoever I lay hands, he may receive the Holy Ghost. But Peter said unto him, Thy money perish with thee, because thou hast thought that the gift of God may be purchased with money. Thou hast neither part nor lot in this matter: for thy heart is not right in the sight of God. Repent therefore of this thy wickedness, and pray God, if perhaps the thought of thine heart may be forgiven thee. For I perceive that thou art in the gall of bitterness, and in the bond of iniquity.


Simon wanted to subjugate the Holy Spirit to himself.  This is always a sign of a false teaching for then God would be confined to the availability of a man for the laying on of hands. We know that Jesus Christ Himself sends the Holy Spirit.


  Ephesians 1:13 In whom ye also trusted, after that ye heard the word of truth, the gospel of your salvation: in whom also after that ye believed, ye were sealed with that holy Spirit of promise


So the answer to this question is that prayer was the effective agent and only Simon the Sorcerer believed that it was subject to the laying on of hands.

When Cornelius and his guests received the Holy Spirit it was without laying on of hands and prior to baptism.


  Acts 10:44 While Peter yet spake these words, the Holy Ghost fell on all them which heard the word.