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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:19:16+00:00 2026-05-24T14:19:16+00:00

How can I make a post request using cookies from php. My php code:

  • 0

How can I make a post request using cookies from php.

My php code:

<?php
$time_start = microtime(true);
$id=$_GET[id];

$data = http_build_query( array ('act' => 'load_friends_silent', 'al' => '1', 'gid'=>'0' ,'id'=>$id) );


$opts = array(
  'http'=>array(
    'header'=>"Cookie:     something=asdaefefe",
'method'=>"POST",
'content' => $data
  )
);

$context = stream_context_create($opts);
print $context;
$contents = file_get_contents('http://vkontakte.ru/al_friends.php', false, $context);

$fil=fopen("./".$id."ne.txt","w");
echo '<br><br>'.$contents;

fputs($fil,$contents);    

fclose($fil);
chmod("./".$id."ne.txt", 0777);

$time_end = microtime(true);
$time = $time_end - $time_start;
echo "<br><br>execute time $time seconds\n";
?>

But this code won’t work on the server; cookie not sent.

  • 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-24T14:19:16+00:00Added an answer on May 24, 2026 at 2:19 pm

    [EDIT]
    To use PHP to post to a page that the user will NOT navigate to, you can use CURL:

    http://davidwalsh.name/execute-http-post-php-curl

    Where in the example, you set $fields to your cookie values:

    $fields = array(
        'lname' => urlencode($_COOKIE['last_name'] ),
        'fname' => urlencode($_COOKIE['first_name'] ),
        ...
    );
    

    [EDIT AGAIN]
    By your newly posted code it looks like you are trying to create a cookie on the page that you are posting to. First of all, creating cookies for other websites would seem to be a big security risk, so I’m 99.9% certain that this has never been nor ever will be possible. Secondly, PHP is not a browser and can’t store cookies for other sites…so even if your post created a cookie, the user’s browser would not have that cookie. All you can do is post ‘something’=> urlencode(‘value’), and then the page you are posting to will have to create the cookie on their end. However, since PHP can’t hold cookies since it’s not a browser, this would be pointless.

    If you want the user’s browser to have a cookie, then you need to use something like jQuery’s $.post. Using jQuery’s post() method will use the user’s browser to go to the page and post data. The page that gets the posted data can then create a cookie on the user’s browser.

    [Read These] they may contain some info for you. Is this what you’re trying to do?

    Simulating a cookie-enabled browser in PHP

    Simulating a POST with PHP & cURL

    It does sound like CURL should be able to mimic a browser’s cookie capabilities…so you might be able to send cookie data, though, as I said, you woudln’t be able to set the user to those cookies or anything…since I’m not sure of your purpose, that makes an answer harder:

    http://php.net/manual/en/function.curl-setopt.php

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

Sidebar

Related Questions

I am using the Zend Framework and using Zend_Http_Client to make a POST request
I can make a DAO recordset in VB6/Access do anything - add data, clean
Sometimes a labeled break or continue can make code a lot more readable. OUTERLOOP:
I can make Firefox not display the ugly dotted focus outlines on links with
In C# you can make a block inside of a method that is not
so that you can make your program concurrent easily in the future.
I know that I can make a setter that checks to see if a
Is there anyway I can make the process of adding references to C# projects
Now that I can make useful user controls in WPF (thanks to this stackoverflow
I'm a pretty inexperienced programmer (can make tk apps, text processing, sort of understand

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.