homepage Welcome to WebmasterWorld Guest from 54.227.41.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
External Javascript help
passing variables from one page to another through a query string
dgIceman




msg:1479622
 3:37 pm on Jun 15, 2003 (gmt 0)

Help me! I'm trying to do an external login script so it's harder to hack. I don't feel going through the CGI process so here's the code:

The login page -

<HTML>
<HEAD>
<TITLE>Member Info</TITLE>
</HEAD>

<BODY BGCOLOR="black" TEXT="white">

<CENTER><H2>Player Login</H2></CENTER>
<CENTER>

<TABLE BORDER=1 CELLPADDING=10>
<TR><TD>
<FORM METHOD="Login" ACTION="verify.html">
</CENTER>User: &nbsp &nbsp <CENTER><INPUT TYPE="text" NAME="ID" WIDTH=10><BR>
</CENTER>Pass: &nbsp &nbsp <CENTER><INPUT TYPE="password" NAME="PW" WIDTH=10>
<BR>

<CENTER>
<INPUT TYPE="submit" VALUE="Login" onClick="function Login()">&nbsp<INPUT TYPE="reset" VALUE="Reset">
</CENTER>

</TD></TR>

</TABLE>
</CENTER>

</BODY>
</HTML>

The actual performing script page -


<HTML>
<HEAD>
<SCRIPT LANGUAGE="javascript">
<!-- PASSWORD PROTECTION PROGRAM -->
<!-- Begin
function Login()
{
var done=0;

var ID=ID;
ID=ID.toLowerCase();

var PW=PW;
PW=PW.toLowerCase();

if (ID=="xxx" && PW=="xxx") { window.location="thankyou.html"; done=1; }
if (done==0) { alert("You have typed in an invalid Character Name and/or Password. Please try again."); }
}
// End -->
</SCRIPT>
</HEAD>

<BODY onLoad="Login()">

It will load the script page but cannot find the ID and PW variables loaded from the previous page; however, in the Address line it shows this:

file:///blah blah/verify.html?ID=xxx&PW=xx

but still cannot find variables.

Help!

 

tedster




msg:1479623
 8:29 pm on Jun 15, 2003 (gmt 0)

Welcome to WebmasterWorld, dgIceman

...cannot find the ID and PW variables loaded from the previous page;
however, in the Address line it shows this:
file:///blah blah/verify.html?ID=xxx&PW=xx

JavaScript variables only exist on a per page basis as objects you can address. So you need to perform some "surgery" to extract the variables from the URL's query string, using JavaScript's substring() method.

The substring() method takes two arguments: the start position and the end position of the substring being extracted. Not to be confused with the substr() method -- that takes a start position argument, and the length of the requested substring from there on.

fullURL = document.URL
qString = fullURL.substring(fullURL.indexOf('?')+1, fullURL.length)

That much gives you a variable named qString which contains everything after the question mark. Then you'll need to chop qString up into its two parts so you can declare your ID and PW as objects for THIS page.

I'll leave that part as a homework exercise ;)

[edited by: tedster at 10:23 pm (utc) on June 15, 2003]

TheWhippinpost




msg:1479624
 9:42 pm on Jun 15, 2003 (gmt 0)

Welcome dgIceman.

Are you sure this is secure enough for your needs? It'd take approximately 15 seconds to crack such a script.

I don't mean to judge, just to alert you in case you weren't aware.

dgIceman




msg:1479625
 2:51 pm on Jun 16, 2003 (gmt 0)

Yeah I know it's not that hard, but it's just not RIGHT there. It's not really that big of a deal.

Thanks for your concern!

dgIceman




msg:1479626
 3:01 pm on Jun 16, 2003 (gmt 0)

Ok...I really hate to ask this but How do I chop it up, and I suppose it goes ABOVE the other js, right (in the same script)? I'm sorry but i'm not that javascript enabled. Heh.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved