Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 902305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:41:48+00:00 2026-05-15T15:41:48+00:00

I have a web-site based on PHP, to which I would like to add

  • 0

I have a web-site based on PHP, to which I would like to add a members-only area. Instead of creating my own registration/login pages, I would like to make a piece of code which will look if the user is logged on a particular site (for simplicity, we could assume that this site is Facebook) and if yes, allow him to navigate on my site. If no, tell him to log on on that site and come back after that.

I would like to accomplish this by making my site open a page on that site, that has a welcome screen if the user is logged in or requires the username/password otherwise. By analyzing the content of that page, I would be able to see if the user is logged in or not.

I have tried to achieve this by using CURL (see the code below), but did not succeeded, as even if the user was logged in on that site via the same browser, when opening my site it was shown as if he wasn’t. I suppose that the problem is in the cookies, as I have somewhere read that while making CURL requests the cookies saved in the browser are not available.

Is there any way to make a PHP script open a page from another site, using the cookies stored in the browser (the cookies were created previously by that site)?

Here is the PHP code from my site:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'www.my-site.com');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, 'User agent');
$data = curl_exec($ch);
echo($data);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:41:48+00:00Added an answer on May 15, 2026 at 3:41 pm

    I actually think this is a really good question. So here are some thoughts.

    First, cookies are explicitly designed not to allow this to happen. Think about it: when you go to facebook.com from home, then that’s great – fbook uses cookies to keep track of your login status and that cookie is bound to your browser session. Someone else checking facebook from their office would have no knowledge of your login – because it’s just a completely different request from a different browser on a different computer with a different IP address and a different set of cookies. So far so good.

    So think about it: you log onto facebook from your computer. Now you open up this special web page – which is trying to use cURL to see information about your session (whether or not you’re logged in.)

    Well “opening a curl session” is equivalent to “opening a browser session” – right? Only your “web browser” has a different interface – commandline versus gui.

    Which means that cURL is effectively a separate entity from a separate domain opening facebook, just like the office worker checking their page is totally independent from yours.

    Moreover, cookies are implemented in browsers such that one domain (user382155.com) is not allowed to access cookies from another domain (facebook.com). This is for security reasons.

    So how can you accomplish this? Here are some ideas. (Some of these are bad ideas. But the idea is to start thinking about solutions.)

    1. You could run your cURL script on the same computer as your web browser. You know, run a web server locally. Then you could play with apache/php settings so that your PHP script can access your browser’s cookie files. Then your script could use that cookie information to determine whether or not to let you log on. Or redirect you to a website on your own domain (bad idea). Or something.

    2. You could use some clever firefox extension or greasemonkey script to do this “cross site scripting” for you – to check the status of facebook cookies and use that to auth your own website. This is in line with the previous suggestion. The problem is that you need the client to install a script of some sort. You might be able to do something clever with javascript but I doubt it – that’s exactly what an “XSS” attack is.

    3. You could monitor the login process of facebook and try to reverse-engineer what it’s doing. I’d recommend LiveHTTPHeaders to help with this. Then you could have your web form get the fbook username/password and then use cURL to “mimic” the login process using that information. This might be against facebook’s policies. (of course, substitute “facebook” with whatever website you’re interested in. In the case of Facebook, this is explicitly against their policies.)

    None of these are great solutions (and they’re insecure, probably violate ToS, blahblahblah). You’re trying to do something which the web is explicitly designed not to do.

    After all that, to answer your question: no, there is not a way for one domain to access the cookies of another domain. (But you can sure try!)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web-based application that notifies users of activity on the site via
I have a web site which I download 2-3 MB of raw data from
I have a web site in asp.net that uses a master page. In this
I have a web site using apache httpd as the server and mysql as
I have a web site running via IIS7 on Vista. The site is running
I have a web site that is a customer to customer (C2C) service. Example,
I have a web site that I administer that uses Apache 2.0 on the
I have a web server with my web site and I am trying to
I have some static images in a folder on my IIS 6-based website that
I have an existing website that uses the same code base, but is deployed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.