Forum Moderators: coopster
The script is apparently incomplete, because after doing some research, it seems some or all of it should be wrapped in a class - but the script does seem to be object-oriented. Unfortunately, I am not a seasoned Object-Oriented PHP developer, so I'm not really sure how to go about fixing it.
The error I receive is Parse error: syntax error, unexpected T_PRIVATE ... on line 132 (line 132 is the first line of code - private Cookie Login())
This is the code for the login procedure:
private Cookie Login()
{
string username = textBoxUsername.Text;
string password = textBoxPassword.Text;
string loginUrl = textBoxLoginUrl.Text;string postData = String.Format("username={0}&password={1}", username, password);
// Get the web request and its stream.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(loginUrl);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
request.CookieContainer = new CookieContainer();
request.AllowAutoRedirect = false;
Stream requestStream = request.GetRequestStream();
byte[] bytedata = Encoding.ASCII.GetBytes(postData);
requestStream.Write(bytedata, 0, bytedata.Length);
requestStream.Close();
// Get the response and read the auth. cookie type.
HttpWebResponse httpWebResponse = (HttpWebResponse)request.GetResponse();
httpWebResponse.Cookies = request.CookieContainer.GetCookies(request.RequestUri);
string cookieName = string.Empty;
if (httpWebResponse.Cookies["LtpaToken"] != null)
{
cookieName = "LtpaToken";
}
else if (httpWebResponse.Cookies["DomAuthSessId"] != null)
{
cookieName = "DomAuthSessId";
}
// If we found a valid cookie, return it.
if (!string.IsNullOrEmpty(cookieName))
{
Cookie newCookie = new Cookie();
newCookie.Name = httpWebResponse.Cookies[cookieName].Name;
newCookie.Domain = httpWebResponse.Cookies[cookieName].Domain;
newCookie.Value = httpWebResponse.Cookies[cookieName].Value;
newCookie.Expires = httpWebResponse.Cookies[cookieName].Expires;
newCookie.Path = httpWebResponse.Cookies[cookieName].Path;
return newCookie;
}
return null;
}
This code displays the returned XML in a text box:
Cookie cookie = Login();
if (cookie != null)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(textBoxUrl.Text);
request.Method = "GET";
CookieContainer container = new CookieContainer();
container.Add(cookie);
request.CookieContainer = container;
HttpWebResponse httpWebResponse = (HttpWebResponse)request.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream(); StreamReader reader2 = new StreamReader(responseStream, System.Text.Encoding.UTF8);
textBoxXml.Text = reader2.ReadToEnd();
}
I would greatly appreciate any guidance.
Thanks,
*j
[edited by: eelixduppy at 3:35 pm (utc) on July 3, 2008]
[edit reason] removed URL [/edit]
This code is messy, but the first line doesn't make any sense at all. I'm assuming it's suppose to be a private function, so you must declare it as one:
private function Login()
I've been looking through the PHP manual link you sent, but I haven't been able to nail down exactly what I'm missing in my script. Some of the syntax from the script I'm working with seems rather different than what's on the PHP manual OOP page. Does the script I'm trying to work with even work? Or am I just spinning my wheels here?
Would it be possible to convert this OOP-based script to non-OOP PHP?
I really appreciate your help. Thanks!
hehe, I didn't look at much of the script you have except for the first line. The script you have doesn't even look like PHP. You might actually just be "spinning your wheels" here...
[edited by: eelixduppy at 5:42 pm (utc) on July 3, 2008]
I may be able to figure out how to convert most of this to PHP, now that I kind of know what I'm looking at. Any suggestions?
Thanks for all your help!
Not sure about that. You might want to look for another script that does what you want. I would check [phpclasses.org...] or other script repositories.