Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP to PHP

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, I was wondering if someone could do me a real big favour and convert the following script to php. I think it's in JSP. The problem is I understand a small majority of the script and I really need it for my site. If you don't have the time to convert it all could you just convert anything which doesn't seem like basic knowledge and anything todo with cookies. Thanx

Class.forName("org.gjt.mm.mysql.Driver");
conn = DriverManager.getConnection(url, id, pass);

long lTimeNow = ( (new Date()).getTime() / 1000 );

String sXMBLVA = "";
String sXMBLVB = "";
String sXMBUser = "";
String sOnlineUser = "";
long lCurrtime1 = lTimeNow + (86400 * 365);
long lCurrtime2 = lTimeNow + 600;
long lTheTime;
String sCookiePath = "";
String sCookieDomain = "";
String sIPAddress = request.getRemoteAddr();
String sLocation = request.getRequestURI();
String sQueryString = request.getQueryString();

if ((sIPAddress.indexOf("216.239.46.") == -1) &&
(sIPAddress.indexOf("64.152.75.") == -1))
{
try
{
Cookie[] cookies = request.getCookies();

if ( cookies != null )
{
for (int i = 0; i < cookies.length; i++ )
{

String sCookieName = cookies.getName();
if (sCookieName.equals(&quot;xmblva&quot;))
{
sXMBLVA = cookies.getValue();
}
else if (sCookieName.equals(&quot;xbmlvb&quot;))
{
sXMBLVB = cookies.getValue();
}
else if (sCookieName.equals(&quot;xmbuser&quot;))
{
sXMBUser = cookies.getValue();
}
}
}

Cookie cCookie1 = new Cookie(&quot;xmblva&quot;, &quot;&quot; + lTimeNow);
Cookie cCookie2 = new Cookie(&quot;xmblvb&quot;, &quot;&quot;);

cCookie1.setMaxAge(86400 * 365);
cCookie1.setDomain(sCookieDomain);
cCookie1.setPath(sCookiePath);

response.addCookie(cCookie1);

if (sXMBLVB.length() > 0)
lTheTime = Long.parseLong(sXMBLVA);
else
lTheTime = lTimeNow / 1000;

cCookie2.setValue(&quot;&quot; + lTheTime);
cCookie2.setMaxAge(600);
cCookie2.setPath(sCookiePath);
cCookie2.setDomain(sCookieDomain);

response.addCookie(cCookie2);

if ( sXMBUser.length() > 0 )
{
sOnlineUser = sXMBUser;
sql = &quot;Update xmb_members set lastvisit='&quot; + lTimeNow + &quot;' where username='&quot; + sXMBUser + &quot;'&quot;;
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
stmt.close();
}
else
{
sOnlineUser = &quot;xguest123&quot;;
}

if (sQueryString != null) sLocation += &quot;?&quot; + sQueryString;

sLocation = &quot;<a href=\&quot;&quot; + sLocation + &quot;\&quot;>&quot; + sLocation + &quot;</a>&quot;;

long lNewTime = ( (new Date()).getTime() / 1000 ) - 600;
sql = &quot;Delete from xmb_whosonline where &quot;;
sql += &quot; (ip='&quot; + sIPAddress + &quot;' && username='&quot; + sXMBUser + &quot;') OR &quot;;
sql += &quot; ip='&quot; + sIPAddress + &quot;' OR username='&quot; + sXMBUser + &quot;' OR &quot;;
sql += &quot; time < &quot; + lNewTime;
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
stmt.close();

sql = &quot;Insert into xmb_whosonline VALUES('&quot; + sOnlineUser + &quot;', '&quot; + sIPAddress + &quot;' , '&quot; + lTimeNow + &quot;', '&quot; + sLocation + &quot;')&quot;;
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
stmt.close();

sListUsers = &quot;&quot;;
int iCountGuests = 0;
sql = &quot;Select username from xmb_whosonline where location = '&quot; + sLocation + &quot;' order by username&quot;;
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next())
{
String sUsername = rs.getString(&quot;username&quot;);

if (!sUsername.equals(&quot;xguest123&quot;))
{
if (sListUsers.length() > 0)
sListUsers += &quot;, &quot; + &quot;<a class=\&quot;link\&quot; href=\&quot;&quot; + sLinkPath + &quot;forum/member.php?action=viewpro&member=&quot; + java.net.URLEncoder.encode(sUsername) + &quot;\&quot;>&quot; + java.net.URLEncoder.encode(sUsername) + &quot;</a>&quot;;
else
sListUsers = &quot;<a class=\&quot;link\&quot; href=\&quot;&quot; + sLinkPath + &quot;forum/member.php?action=viewpro&member=&quot; + java.net.URLEncoder.encode(sUsername) + &quot;\&quot;>&quot; + java.net.URLEncoder.encode(sUsername) + &quot;</a>&quot;;
}
else
{
iCountGuests++;
}
}

// if no members, display &quot;None&quot;
if (sListUsers.length() == 0) sListUsers = &quot;None&quot;;

// display Guests if there are any
if (iCountGuests == 1) sListUsers += &quot; (1 Guest)&quot;;
if (iCountGuests > 1) sListUsers += &quot; (&quot; + iCountGuests + &quot; Guests)&quot;;

bCookiesOn = true;
}
catch(java.lang.NoClassDefFoundError ex)
{ %>
<!--caught an error here-->
<% }
}
conn.close();
 
This is my opinion...

This is a PHP tips phorum, it's like a phorum where we discuss PHP related problems, and we help user solve there problems in PHP. To convert from one language to another, you should do yourself, or instead, just pay someone to do that job for you...

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
you said it all, understand problems, not do their jobs.

That's why i said that. Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
I'm gonna agree guys, I'll try and help anyone who'll help themselves, If people want to learn I'll help, if people want to be lazy, so will I :) ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top