Here is the code:

$ch = curl_init('http://site.com/indexNew.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "user=test&password=test"); curl_setopt($ch, CURLOPT_REFERER, "http://pworlds.ru/"); curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); curl_close($ch); 

In theory, we send the request http://site.com/indexNew.php?user=test&password=test, while storing the cookie in my_cookies.txt.

How to do this: first send a request to http://site.com/indexNew.php?user=test&password=test, and then go to http://site.com/test.php, but at the same time cookies should not be lost ( page is available only to authorized users).

Thank you in advance.

  • @JavaBitz The title should reflect the meaning of the question. - Nicolas Chabanovsky
  • I'm new to php :) - JavaBitz

1 answer 1

add:

 curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt"); 
  • how to go to test.php after logging in? - JavaBitz
  • header ("location: localhost / test.php" ); - Node_pro
  • one
    Just execute another query: $ ch = curl_init (' site.com/indexNew.php' ); curl_setopt ($ ch, CURLOPT_REFERER, " site.com/indexNew.php" ); curl_setopt ($ ch, CURLOPT_COOKIEJAR, "my_cookies.txt"); curl_setopt ($ ch, CURLOPT_COOKIEFILE, "my_cookies.txt"); curl_exec ($ ch); curl_close ($ ch); - chernomyrdin