[PHP] automatic post

u5uckm3

New Member
hi,

ich want to perform an automatic post in a vB forum with php.

my idew was to solve this problem with the function http_post_fields(), but my problem is atm, that i can't login to the forum.
If i try to post a message, my result is the vB login page.
I tryed to login with cookies, like in the example at php.net, but it didn't work with vB.

Anyone have a idee?

heres my code:
PHP:
$url = 'http://andy-server/forum/3.vb/newthread.php?do=newthread&f=4';

$data = array('subject' => 'test-betreff', 'message' => 'inhalt bllsadfjafh');

$files = array();
$options = array(
                 'bbpassword' => '76e93f0f0f3a8018e80d367fae3905ae', // md5hash of the pw
                 'bbuserid'   =>  '2', // userid
                 'bbsessionhash' => '326e0f19bebbaa837a60c8d52c9dc71d' //  session is, just for testing but it didn't work (i created the session before with the browser)
                );

$req = http_post_fields($url , $data, $files, $options);

echo $req;

btw, sry for my bad english xD
 
vB uses a:

action="login.php?do=login" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, $show[nopasswordempty])"

For the password, it also calls the vbulletin_md5.js file

With a basic login script, something like will should work:

PHP:
<?php

$forumpath = "http://www.yoursite.com/forums/";

// We check if user is logged in
if ($vbulletin->userinfo['userid']!=0) {

// If Logged in display welcome back message
echo "Welcome Back, <b>";
echo $vbulletin->userinfo['username'];
echo " !</b><br />";

// If logged in display logout link
echo "<a href=\"".$forumpath."login.php?$session[sessionurl]do=logout&logouthash=$logouthash";
echo $vbulletin->userinfo['logouthash'];
echo "\">";
echo "<font size=\"1\" face=\"verdana\">Log Out</font></a>
";

} else { // If user is not logged in, we do this stuff

// Display text and link to register.
echo "
	You have to <a href=\"".$forumpath."register.php?s=$session[sessionhash]\"
	target=\"_parent\"><b>register</b></a>  before you can post on our forums or use our advanced features.
	";

// Display login boxes + button
// You can style this with html or CSS as normal if desired.
echo"
	<form action=\"".$forumpath."login.php\" method=post onsubmit=md5hash(vb_login_password,vb_login_md5password,vb_login_md5password_utf)>
	<script type=text/javascript src=\"".$forumpath."clientscript/vbulletin_md5.js\"></script>
	User Name:<br />
	<input name=vb_login_username type=text id=navbar_username onfocus=\"if (this.value == '$vbphrase[username]') this.value = '';\" size=10 />
			
	<br />Password:<br />
	<input name=vb_login_password type=password size=10 />
	</br>
		
	<label for=cb_cookieuser_navbar><input name=cookieuser type=checkbox id=cb_cookieuser_navbar value=1 checked=checked />
	Remember Me?<br /></label>
	
		
	<input type=submit title=$vbphrase[enter_username_to_login_or_register] value=\"Log In\" />
		
	<input type=hidden name=s value=$session[sessionhash] />
	<input type=hidden name=do value=login />		
	<input type=hidden name=vb_login_md5password />
	<input type=hidden name=vb_login_md5password_utf />

	</form>
";

}
?>

Then you call that with another PHP file:

PHP:
<?php
$curdir = getcwd ();
chdir('/path/to/your/forums');
require_once('/path/to/your/forums/global.php');
chdir ($curdir);
?>

After this you have your 
<HTML> and <BODY> tags

Then call the first file with..

<?php
   require_once('/path/to/your/login_inc.php');
?>

This is the backbone for your login, after that you can do your post functions.

What exactly are you trying to post? There may be much better ways of doing this depending on what you want to do, for instance using the RSS poster Robot to feed your content directly to the board.

Check in Admincp >> RSS Feeds >> RSS Feed Manager

Have a look at that, it may do what you want very easy.
 
Top