A judge on Wednesday ordered a man accused of showing up at Lindsay Lohan's court appearances and leaving gifts at her house to stay away from the actress for the next two years.

Los Angeles Superior Court Judge Joseph Biderman issued the restraining order against David Cocordan after a hearing in Santa Monica, Calif. Neither Lohan, who is serving house arrest, nor Cocordan attended the hearing.

Biderman said the man had filed a statement agreeing to the stay-away order.

Lohan wrote in a court filing last month that she is frightened of Cocordan, 38, who she stated had sent her more than 100 text messages, including one describing having sex with the "Mean Girls" star.

The actress is serving house arrest on a 120-day jail sentence for violating her probation by taking a necklace without permission from a jewelry store in January. She is expected to serve about 35 days.

One text message contained in the court documents indicates Cocordan was in the courtroom last month when the 24-year-old actress was sentenced to jail.

Lohan's attorney, Blair Berk, told the judge that police officers would serve the two-year restraining order on Cocordan, who according to court records lives in Glendora. That is about 45 miles east of Lohan's home in the beachside community of Venice.