doupin2013 2010-07-21 14:41
浏览 53
已采纳

C#:如何将PHP会话变量发送到WebBrowser控件?

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
");

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 $_SESSION 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!

  • 写回答

1条回答 默认 最新

  • doumian3780 2010-07-21 15:05
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用