2

I am trying to send a post request that does the excact same thing as the code below, but from a php file to another php file. In other words I want to make the post request with PHP and not Javascript. I have tried different methods but they all get the content from the php file, and not make the post like ajax.

$.ajax({
    url: "./delete.php",
    method: "POST",
    data: {
        id: 1
    },
    success: data => console.log(data),
    error: err => console.log(err)
})
3
  • can you provide the php code that you've tried? Commented Aug 8, 2021 at 20:00
  • 1
    If you use curl() it should make the POST request. You would get the content if you use file_get_contents(). Commented Aug 8, 2021 at 20:01
  • 1
    Does this answer your question? stackoverflow.com/questions/6560512/… Commented Aug 8, 2021 at 20:18

1 Answer 1

2

This is the code sample I used. Thanks to @Amirhossein Shahbazi for the suggestion. Link to the question: send http request with CURL to local file

<?php
$url = 'http://localhost:8000/fe.php';
// The submitted form data, encoded as query-string-style
// name-value pairs
$body = 'monkey=uncle&rhino=aunt';
$c = curl_init ($url);
curl_setopt ($c, CURLOPT_POST, true);
curl_setopt ($c, CURLOPT_POSTFIELDS, $body);
curl_setopt ($c, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec ($c);
curl_close ($c);
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.