• Resolved Grigory Volochy

    (@grigory-volochiy)


    I’m writing a plugin, which should be able receive data from remote server and save data to the site Data Base.

    The main problam is that if I try to send request from remote server to the .php file that uses native WordPress functions – the WP ignores this request and the script does not receive any data.

    The solution which I found is the next:
    I receive the data (from remote server) by using .php file that saves this data in the .txt file. After that, I invoke .php file that use native WP functions and save data from this file to the Data Base. I understand that this is like a cheat the WP security.

    But I need to know: is here a way to receive data from remote server and directly save to the Data Base using native WP classes for working with Data Base, without using extra file like that .txt file.

    Also, using native WP function with DataBase makes the work more safe.

    I already used the “Plugin API/Action Reference/admin post (action)”. But it allows to receive data as logged site admin (like from my own admin page). I need to receive data from remote server by the plugin without admin access, and I can take the risk on myself, but I want to use the native WP functions to receive that request and work with DataBase.

    Is it possible?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Grigory Volochy

    (@grigory-volochiy)

    It seems like I found solution:
    I was trying to retrieve data from POST request using $_POST, and it seems like it is unavailable in the .php files which use native WP functions. But when I try to use $_REQUEST – I can retrieve data from POST request.

    Moderator bcworkz

    (@bcworkz)

    I’m glad you were able to figure out a solution. As a possible explanation for your observations, it sounds like the requested data was coming by way of $_GET — this explains why $_POST does not work and $_REQUEST does.

    FWIW, some consider $_REQUEST a slight security risk because cookie values can override $_GET values using the same key, allowing a bad actor to substitute arbitrary values via forged cookies. As long as you properly sanitize and validate all incoming data I don’t think the risk is very significant.

    Thread Starter Grigory Volochy

    (@grigory-volochiy)

    Thanks a lot for interest to my problem. But I decided try to use $_REQUEST instead of $_POST, because I found this
    And one commentator said that he got the same problem (with $_POTST), when he updated his WP to 3.0 (instead 2.9.2).

    Thread Starter Grigory Volochy

    (@grigory-volochiy)

    Also, when I first write that plugin (using $_POST) – it properly worked on my local server, but when I install it on my site on external server – it stop the work, and I spent a lot time to understand what wents wrong.

    Thread Starter Grigory Volochy

    (@grigory-volochiy)

    Since I did not find any mention about not working $_POST for incoming request in WordPress documentation – it is a bug of WordPress?

    Moderator bcworkz

    (@bcworkz)

    If both $_POST and $_GET contain no data and $_REQUEST does then the only place where the data could possibly come from is $_COOKIE, which is likely stale data and will fail for a new user. This is yet another issue with $_REQUEST, it gives the illusion something is working when it is not.

    It’s difficult for me to imagine WP would have a bug this fundamental this far into it’s release cycle. By now it’s been tested by thousands of people in thousands of ways. Is a bug possible? Yes. Is it probable? Extremely unlikely. Unless you can provide code or instructions for others to replicate your results we’re going to have to assume the fault lies on your end. Don’t take offense, we’ve all been in your position at one time or another.

    From your descriptions so far, it sounds like you are requesting a custom .php page that contains WP core functions. Whether from a remote server or browser I don’t think matters at all. Directly requesting a custom .php page containing core functions is flawed already. Either the WP environment is never initialized or it is initialized incorrectly.

    You mentioned the admin_post_$action hook. This is one way to properly initialize the environment, if used correctly. You don’t give details, but requesting a custom .php page will result in the action never firing. The request must go through admin-post.php for this method to work. Unless you have additional wp-admin security outside of WP, it would not matter if the user is logged in as admin or not logged in at all, the method remains valid.

    It’s not uncommon to run into issues when moving from a localhost to a hosted server. The problem often is solved by accounting for different versions of PHP, mySQL, or by different server settings in php.ini or the applicable .conf files.

    Thread Starter Grigory Volochy

    (@grigory-volochiy)

    Since the using remote post requests can be useful for me in future, I will make the more comprehensive tests with that problem. But at nearest days it is impossible.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Receive data from remote server and save it in data base by plugin’ is closed to new replies.