3:05 PM PT -- 7/8 -- A judge has granted Kim a 5-year permanent order of protection against Costanza.
Kim Kardashian now has legal protection against the man who allegedly showed up to her home on multiple occasions and sent a package containing Plan B and a diamond ring ... thanks to a restraining order.
KK filed docs Wednesday against Nicholas Costanza, whom she claims is the person who disturbingly shipped Plan B pills and an engagement ring to her home earlier this month ... a package that was intercepted by Kim's security team.
In her filing -- from attorney Shawn Holley-- Kim says Costanza has shown up to her property a handful of times this year ... including once in February, and then again in late May. She claims he sprung up at her gated community, telling guards he was there to pick her up for dinner on one occasion.
On top of the alleged behavior ... Kim says Costanza's been obsessing over her online as well -- posting a bogus marriage cert and other bizarre messages, alluding to her waiting for her "knight in shining armor" (which he clarified as himself).
A judge agreed with Kim's concerns and granted the temporary order ... Costanza will have to stay at least 100 yards away and refrain from contact.
This ain't the first alleged stalker who's been trying to get at her either -- remember, she filed for and received a separate restraining order against another man who said he was just dying to get into her pad.