Support » Developing with WordPress » sessions in ajax request

  • I have an API, when I call it from my PHP script, it creates new session data. I want to call API with my same session data. I used wp_remote_post function to call my api.

    I cannot hack into API so I need to make changes in my script where I am requesting.

    Shall I pass any additional parameter to wp_remote_post function or please suggest any another method I can use to call my API.

    Thanks and regards

Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    Your script creates a new session or the API does? If the API, how to get it to use an existing session would depend on the API. If your script, after you call session_start(), check if your value is in $_SESSION. If it’s not there, there never was a session, so start afresh. Otherwise use the existing data in $_SESSION.

    Some alternatives to the HTTP API methods (wp_remote_post() etc.) are cURL and PHP’s native file_get_contents(). cURL is very configurable, but it takes a little doing to setup a request, and it’s not available on all servers. I suggest you stay with HTTP API instead of using file_get_contents().

Viewing 1 replies (of 1 total)
  • The topic ‘sessions in ajax request’ is closed to new replies.