I'm trying to produce a single sign up experience between an asp.internet site along with a wordpress site utilizing a simple form Publish method. I've built an easy php page that utilizes the native wordpress functions wordpress_place_user and wordpress_signon to produce user account within the mysql db and sign them in. During my asp.internet 'create new user' page code behind, I am while using publish approach to an HttpWebRequest to transmit the needed information towards the php page.
It almost works! The brand new wordpress user is produced within the mysql database, but they're not drenched in. How do i get wordpress to log them in?
UPDATE 11/29/11. I have added the code I did previously understand this working. See below
Here's my HttpWebRequest
Public Sub LoginToWordpress()
'This enables single sign on between our asp.net site and wordpress.
Try
'get the values
Dim uid As String = TxtLogin.Text
Dim pwd As String = TxtPassword.Text
'format and encode the input data
Dim encoding As New ASCIIEncoding()
Dim postData As String = ("&UserName=" & uid)
postData += ("&Pwd=" & pwd)
Dim data As Byte() = encoding.GetBytes(postData)
Dim cc As New CookieContainer()
'Prepare web request...
Dim myRequest As HttpWebRequest = WebRequest.Create("http://www.mywebsite.com/speciallogin.php")
myRequest.Method = WebRequestMethods.Http.Get
myRequest.Method = "POST"
myRequest.ContentType = "application/x-www-form-urlencoded"
myRequest.ContentLength = data.Length
myRequest.CookieContainer = cc
Dim newStream As Stream = myRequest.GetRequestStream()
'submit the php form for BuddyPress signup
newStream.Write(data, 0, data.Length)
newStream.Close()
'Get the response
Dim myResponse As HttpWebResponse = myRequest.GetResponse()
Dim reader As New StreamReader(myResponse.GetResponseStream())
'Look for cookies in the response
If Not myResponse.Cookies.Count = 0 Then
For Each c As Cookie In myResponse.Cookies
'Write the wordpress cookie to the browser
Dim cookiename As String = c.Name
Dim cCookie As New HttpCookie(cookiename)
cCookie.Value = c.Value
cCookie.Expires = c.Expires
cCookie.Domain = ".mywebsite.com"
cCookie.Path = "/"
Response.Cookies.Add(cCookie)
Next
End If
myResponse.Close()
Catch ex As Exception
Response.Write(ex)
End Try
End Sub
This is actually the php page (speciallogin.php)
<?PHP
include 'wp-load.php';
require_once( ABSPATH . WPINC . '/user.php' );
require_once( ABSPATH . WPINC . '/pluggable.php' );
//get the variables from the post of another page
$u_username = $_POST['UserName'];
$u_password = $_POST['Pwd'];
//build the array
$creds = array();
$creds['user_login'] = $u_username;
$creds['user_password'] = $u_password;
$creds['remember'] = true;
//log the user in
$user = wp_signon( $creds, false );
if ( is_wp_error($user) )
echo $user->get_error_message();
//see what happened
if ( is_user_logged_in() ) {
echo'log in failed'.'<br>';
} else {
echo'login success!"<br>';
}
wp_get_cookie_login() ;
print_r($_COOKIE);
?>