Forum Moderators: coopster

Message Too Old, No Replies

Using a PHP script at command line

Automated forum posts

         

trillianjedi

8:23 pm on Aug 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm way out of my depth on this one and I'm not even sure if it's possible.

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

ergophobe

9:07 pm on Aug 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Not sure about that button URL and don't know PNphpBB2, but on the demo at opensourcecms.com it's just a normal form with an action that submits to posting.php with a 'post' flag rather than 'preview'.

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.

trillianjedi

9:23 pm on Aug 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks ergophobe, I think you're advising that I simply call the functions inside the script, rather than call the script?

I'll have a go...!

Thanks,

TJ

grandpa

7:58 am on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



<OT>
I'll have a go
Go easy TJ, or you may find yourself modding in forum 88. I heard a rumor that there could be an opening there.
</OT>

Angelis

8:26 am on Aug 15, 2005 (gmt 0)

10+ Year Member



You could just post the values straight into the database, phpBB is good for that as it sets an auto number for the post you just need to fill the rest of the details in.

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...

vbbnn

8:31 am on Aug 15, 2005 (gmt 0)

10+ Year Member



In Windows, you may use

C:\>php.exe -f "C:\Apache2\htdocs\webSite\script.php"

or create a bat file with the above line.

The path should be known to the system, otherwise you add your path in font of php.exe

ergophobe

4:11 pm on Aug 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I suspect Angelis is right and realistically that's probably how I would do it left to my own, but I don't know phpBB and TJ said he didn't want to do it that way. In thinking about it though, someone wrote all the logic for posting it, so why not just use their script anyway instead of writing out my own queries?


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.

jatar_k

5:42 pm on Aug 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



we used to use procmail to read emails and auto post them to phpbb.

worked fine, I will see if I can dig up what and we posted it, not sure where that script went.