问题
I'm working on a website that has a forum area, I will probably use the SMF forum software for the forum. Users can register and log in on the website. I would like to achieve that when they register on the website, they get also registered on the forum (they don't have to register twice). And also when they log in to the website that would also log them into the forum so they don't have to log in twice.
I think this should be possible with curl but I need to see some example code so I can figure it out. The main problem is that on the registration page there is a captcha so I don't know how to get over that.
回答1:
There's a post on the SMF forums that explains how to post a topic with cURL. http://www.simplemachines.org/community/index.php?topic=53433.0
You could use the same method for registration, just using different form variables
Addendum:
The main problem is that on the registration page there is a captcha so I don't know how to get over that.
I think the point is that you're not supposed to bypass the captcha.
回答2:
The basic steps to this are simple.
First, the Registration. When you register on the main site, simply add a Database entry to the Forum's database with the correct user information:
INSERT INTO TABLE (`Field1`, `Field2`) VALUES(`Value1`, `Value2`)
The next part is a bit trickier.
If you feel comfortable editing the source of the forum, you simply have to find where they check the login cookies, and add in a check for your cookie aswell. (Given they are on the same domain.)
if(checkSiteCookie() == true) { // ... do stuff ...
turns into
if(checkSiteCookie() == true || checkCompanyCookie() == true)) { // .. do stuff..
If the Site and the Forum are on the same domain, you could use the forum's cookie function to set the cookie in your script.
setMyCookie();
setForumCookie();
If you can't, you could always try using AJAX to submit their login form first to your login page, then the forums. After both of them have been completed, redirect them to the proper page.
// Get your Site Cookies and Log In
$.post("mylogin.php", form, function(data){
// Get the Forum's Cookies
$.post("forumlogin.php", form, function(data){
// Reload the Page
window.location.reload(true);
}
});
来源:https://stackoverflow.com/questions/2014232/register-and-login-to-smf-with-curl