Okay, I am using the following code to navigate to a page in my WebBrowser control based on information entered in a login form:
private string currentUser = usernameTextbox.Text;
private string currentPasswd = passwordTextbox.Password;
public static byte[] StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}
Uri myHomePage = new Uri("userHome.php");
currentBrowser.Navigate(myHomePage, "", appFunctions.StrToByteArray("username=" + currentUser + "&password=" + currentPasswd), "Content-Type: application/x-www-form-urlencoded\r\n");
This code works fine and sends the POST data to my desired variables within my PHP page, and it successfully logs the user in to their personal menu. Doing this also sets a $_SESSION variable on the PHP page to hold the username accross all pages of the site. This also works fine - as long as I am navigating from links within the pages themselves. However, if I try to use the WebBrowser.Navigate() to move to another page, it seems to lose the $_SESSION variable.
With all that being said, what I would like to know is if there is any way to send my C# 'currentUser' variable directly to the PHP $_SESSI开发者_运维知识库ON variable via the WebBrowser.Navigate() method.
I think that if I can do this my problem will be solved. If not I'll probably have to go through each page of my site and add some variable-checking code to see if the C# form has sent the POST data directly to that page.
Any help will be greatly appreciated!
PHP has two ways to work with sessions: set a cookie, or mangle every URL on the page to include the session identifier.
It sounds like PHP is doing the latter, when you want it to do the former. Make sure your code can work with cookies.
精彩评论