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 6230511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:45:51+00:00 2026-05-24T09:45:51+00:00

I am building an application that is built upon an API that requires Basic

  • 0

I am building an application that is built upon an API that requires Basic Authentication. I have made many calls and wrapped up the CURL requests inside a class that I’ve made,

I’m using a cookie jar that I use like this:

curl_setopt($curl_handle, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($curl_handle, CURLOPT_COOKIEFILE, "cookie.txt");

I am trying to keep sessions by using cookie.txt to store the cookies and its been working great. However, today I came across an alarming discovery. When someone else (on a different computer) goes to my app, they can see my session information (probably because it’s using the same file as reference for the session). I have thought that perhaps I could generate a new “cookie jar” for each visitor, but this will probably not work when it goes to production. The quantity of users is going to be in the thousands at least, so I think this means that I would need a cookie file for each visit right?

This doesn’t seem practical and not to mention that I would have to create the cookie file programmatically. Has anybody else come across this issue before? Any suggestions would be a real help.

Perhaps there’s a CURL setopt solution that would uniquely distribute the cookies amongst visits?

Thanks!

  • 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-24T09:45:52+00:00Added an answer on May 24, 2026 at 9:45 am

    If you can expose the cookie to the user if you turn on curl_setopt($curl_handle, CURLOPT_HEADER,1) the headers returned by the curl exec will be present a the top of the content, you could match these out of the top of the content and pass them to the clients browser for retention, then pass any user cookies back through the curl process for the next request.

    something crude I made a while ago:

      if(is_array($_COOKIE))
      {
        foreach($_COOKIE as $cookiename => $cookievalue)
        {
          if($cookievalue)
          {
            if(get_magic_quotes_gpc())
            {
              $cookievalue = stripslashes($cookievalue);
            }
            $cookies[] = $cookiename .'='. urlencode($cookievalue);
          }
        }
        if(is_array($cookies))
        {
          curl_setopt($curl_handle, CURLOPT_COOKIE,implode('; ',$cookies));
        }
      }
    

    after the curl exec

      preg_match_all('%HTTP/\\d\\.\\d.*?(\\r\\n|\\n){2,}%si', $curl_result, $header_matches);
      $headers = split("\r\n", str_replace("\r\n\r\n",'',array_pop($header_matches[0])));
      if(is_array($headers))
      {
        foreach ($headers as $header)
        {
          preg_match('#(.*?)\:\s(.*)#', $header, $header_matches);
          if(isset($header_matches[1]))
          {
            $headers[$header_matches[1]] = $header_matches[2];
          }
          // SET THE COOKIE
          if($header_matches[1] == 'Set-Cookie')
          {
            header('Set-Cookie: ' . $header_matches[2],false);
          }
        }
      }
      # Remove the headers from the response body
      $curl_result = preg_replace('%HTTP/\\d\\.\\d.*?(\\r\\n|\\n){2,}%si','',$curl_result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an application that calls upon a compiled executable. Said executable's source
I'm building an application that uses an elaborate API to fetch data from Youtube,
I've built (or I'm building) an application that supports a wide variety of languages.
I have a custom application that was built to send opt-in newsletters and marketing
I have a Qt-based application that uses a number of dlls that are built
I have an application which depends on PyGTK, PyGobject, and PyCairo that I built
We have a web application that has been built using MySQL / PHP /
I have an application built upon ASP.NET 3.5 and PostgreSQL 8.3. My database has
I built a web application that uses Yahoo Geocoding API or Google Maps API
We have an application that was built for the Windows Mobile and Windows platforms,

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.