Forum Moderators: coopster
I have a script that runs daily collating statistical data on widgets, and I'd love to have the server automate a post to a pnphpBB2 forum.
I've had a look at the source in the "post a new topic" page, and it seems that the "submit" button calls this:-
/index.php?name=PNphpBB2&file=posting method=post
... with a couple of text fields and hidden form objects containing the meat of the post.
I assume I'd also need to set a cookie (members only forum).
Can I fake this from the command line and get CRON to call it up and have the server make a post automatically?
If so, can anyone point me in the right direction to find out how I go about scripting it?
The rest of the forum engine is quite complex, so I'm not sure I could simply add the data to the DB without causing all manner of other sync issues which are dealt with by the script.
Thanks,
TJ
The posting.php file requires some constants and so forth to be set to prevent it from getting accessed directly. So what I would do is create a file called auto_post.php or something and have it set all the parameters necessary, like
define("LOADED_AS_MODULE", true);
and then just set your variables to the values needed. Amazingly, the latest CVS version is 2 years old and still uses the $HTTP_POST_VARS array.
Anyway, play around for a while to make sure all the right flags are set and variables defined, then just include posting.php in your auto_post.php file. It should take it from there doing whatever it needs to synch various DB tables and so on.
No different than anything else really, you just need to make sure you use the mysql lock when you are adding the record so nothing gets duplicated / not inserted...
I think you're advising that I simply call the functions inside the script, rather than call the script?
No, not exactly. I'm advising a "wrapper" script that sets all the conditions that PNphpBB expects when the posting.php script is called (constants defined as necessary and so forth) and then just including the posting.php script below that.
Your script wouldn't actually call any functions and woudln't need to write any code beyond assigning values to variables as expected by posting.php so it would think that it was being called in the normal fashion. In other words, you would just be setting values, not doing any logic.