Forum Moderators: coopster

Message Too Old, No Replies

Please help with my incomplete script

I have an incomplete script that needs to be fully Object oriented

         

jacosta000

3:29 pm on Jul 3, 2008 (gmt 0)

10+ Year Member



hello. I found a PHP script that is supposed to allow me to login to a Lotus Notes database and display the values from a view in XML. The script is found <snip>

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]

eelixduppy

3:37 pm on Jul 3, 2008 (gmt 0)



Hello and Welcome to WebmasterWorld!

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()

jacosta000

3:42 pm on Jul 3, 2008 (gmt 0)

10+ Year Member



thanks so much for your quick reply!
I tried changing the function declaration to 'private function Login()', but I get the exact same error.
From what I've read, it seems you can't declare anything private/public unless it's in a class. I think that's my problem. I'm just not sure how to stuff it into a class

eelixduppy

3:53 pm on Jul 3, 2008 (gmt 0)



Ahh, I didn't understand that this isn't within a class. You might want to read up on OOP before you delve right into the beast. Here is a good place to start:http://www.php.net/manual/en/language.oop5.php

jacosta000

4:44 pm on Jul 3, 2008 (gmt 0)

10+ Year Member



Can I not just solve this by wrapping some of the code inside of a class? Or am I missing more than I seem to think I am missing?

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!

eelixduppy

4:59 pm on Jul 3, 2008 (gmt 0)



>> Does the script I'm trying to work with even work?

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]

henry0

5:23 pm on Jul 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



looks like .net to me

jacosta000

5:24 pm on Jul 3, 2008 (gmt 0)

10+ Year Member



Oh my goodness! I think you're right!
The page doesn't even mention PHP, I just assumed it was because my search phrase in Google included 'php'. It's probably ASP - that's the extension of the page I'm looking at. i feel like a moron! I'm glad you noticed that - I could've been looking at this forever.

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!

eelixduppy

5:44 pm on Jul 3, 2008 (gmt 0)



>> convert most of this to PHP

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.