自动登录 [英] Auto login
问题描述
我正在用他公司的网站帮助这个人。他们有一个页面,你登录的页面是
,基本上看起来当你输入密码和
用户信息并提交表格时,它会运行一个javascript函数来保存
将信息作为cookie。它看起来像这样:
< script language =" JavaScript">
function savecookie()
{
/ *保存表格输入的用户和密码值
(document.form.elementname)在cookie中* /
var url =" /sap/its/iacproject/select_premises.html" ;;
var nextyear = new Date();
nextyear.setFullYear(nextyear.getFullYear()+ 1 );
document.cookie =''password =''+ document.Login.password.value +
''#expires =''+ nextyear.toGMTString() + ''; path = /'';
document.cookie =''user =''+ document.Login.user.value +'';
expires =''+ nextyear .toGMTString()+'';路径= /'';
}
< / script>
他们希望这样做,以便在您注册时,一个不同的
页面,你可以自动登录。我尝试通过将saveCookie函数复制到注册的最后一页
$ b $来实现这一点。 b处理,并相应地改变变量。这是因为在注册表中有很多SAP,所以它可以获得
fishy。这是来自注册页面的我的
savecookie功能:
< script language =" JavaScript">
函数savecookie()
{
/ *保存cookie中输入表单的用户和密码值
* /
var url =" /sap/its/iacproject/select_premises.html" ;;
var nextyear = new Date();
nextyear.setFullYear (nextyear.getFullYear()+ 1);
document.cookie =''password =
EWEBIAC_HTML_LOGIN_FIELDS-alias_name_RES.value; path = /'';
document.cookie =''user =
EWEBIAC_HTML_LOGIN_FIELDS-PASS_RES.value; expires =''+
nextyear.toGMTString()+'';路径= /'';
}
savecookie();
< / script>
现在,它几乎正常运作。它确实为我保存了cookie,但
值都搞砸了。我认为在为cookie变量分配
时出现语法错误。我希望它只是一些引号或
这里有人能为我识别的东西。我分配变量
是因为SAP看起来如下:
< body`SAP_BodyAttributes()`onLoad ="`SAP_OnLoadJavaScript() `">
`SAP_TemplateFormBegin()`
< h2 style =" font-style:arial" style =" font-size:24pt">`#l_header`< / h2>
`SAP_TemplateGroupBoxBegin(groupboxlabel =#success)`
`SAP_TemplateInfoLine(~messlineline)`
< br>
`SAP_TemplateNonEditableField(" alias_name_RES",
fieldLabel = fieldLabel =#alias_name,
fieldLabelWidth =" 250",value = EWEBIAC_HTML_LOGIN_FIE LDS-alias_name_RES.value,size =" 150")`
< br>
`SAP_TemplateNonEditableField(" PASS_RES",
fieldLabel = EWEBIAC_HTML_LOGIN_FIELDS-PASS_RES.label,
fieldLabelWidth =" 250",value = EWEBIAC_HTML_LOGIN_FIE LDS-PASS_RES.value,size =" 20")`
< br>
`SAP_TemplateNonEditableField(" smtp",
fieldLabel = EWEBIAC_HTML_LOGIN_FIELDS-smtp.label,
fieldLabelWidth =" 250,value = EWEBIAC_HTML_LOGIN_FIE LDS-smtp.value,size =&quo t; 100"
< script language =" JavaScript">
savecookie();
< ; / script>
.....
< snip>
任何人都知道我怎么能得到变量从
之前的表单传递到cookie中?谢谢!
< 11 ******************** **@f14g2000cwb.googlegroups .com>
var passwd = document.forms [''MyFormName'']。
elements [''EWEBIAC_HTML_LOGIN_FIELDS-alias_name_RES ''] .value;
// JavaScript无法解析字符串中的变量,它不是Perl
这里: - )
//还有一个丑陋的名字,其中带有*减*,这总是要求
麻烦:-(
//但它'无论如何,这是你的解决方案...
document.cookie =''password =''+ escape(passwd)+''; path = /'';
// cookie值需要转义(以及cookie名称
//如果你在其中使用一些奇怪的字符,这不是这里的情况)
和其他饼干一样......
VK写道:< 11 **********************@f14g2000cwb.googleg roups .com>
var passwd = document.forms [''MyFormName'']。
elements [''EWEBIAC_HTML_LOGIN_FIELDS-alias_name_RES'']。value;
// JavaScript没有解决字符串中的变量,这里不是Perl
:-)
//还有一个带有*减*的丑陋名字,它始终是一个调用
烦恼:-(
//但无论如何这都是你的解决方案......
document.cookie =''password =''+ escape(passwd)+' ; path = /'';
//需要转义cookie值(以及cookie名称
//如果你在其中使用了一些奇怪的字符,这不是一个例子)
等等其他饼干......
谢谢你的朋友,如果有效,我会把那些评论放在那里
只是为了好玩:)
VK写道:
< 11 **********************@f14g2000cwb.googlegroups .com>
你在拖钓。
[...]
document.cookie =''password =''+ escape(passwd)+' ; path = /'';
//需要转义cookie值(以及cookie名称
//如果你在其中使用了一些奇怪的字符,这不是一个例子)
废话。 `passwd''只需要转义如果它包含一个
`;''因为这已经是cookie值组件分隔符;
a simple passwd.replace(" ;","%3B")就足够了。
PointedEars
Hey gang,
I''m helping this guy with his company''s website. They have a page where
you login, and basically it looks like when you enter your password and
user info and submit the form, it runs a javascript function that saves
the info as a cookie. It looks like this:
<script language="JavaScript">
function savecookie()
{
/* save the values of user and password of the form input
(document.form.elementname) in the cookie */
var url = "/sap/its/iacproject/select_premises.html";
var nextyear = new Date();
nextyear.setFullYear(nextyear.getFullYear() + 1);
document.cookie = ''password= ''+ document.Login.password.value +
''# expires=''+ nextyear.toGMTString() +''; path= /'';
document.cookie = ''user= ''+ document.Login.user.value + '';
expires='' + nextyear.toGMTString() +''; path= /'';
}
</script>
They want to make it so that when you register, which is on a different
page, you can automatically be logged in. I tried doing this by copying
the saveCookie function into the final page of the registeration
process, and changing the variables accordingly. This is where it gets
fishy, because there''s a lot of SAP in the registration form. Here''s my
savecookie function from the registration page:
<script language="JavaScript">
function savecookie()
{
/* save the values of user and password of the form input in the cookie
*/
var url = "/sap/its/iacproject/select_premises.html";
var nextyear = new Date();
nextyear.setFullYear(nextyear.getFullYear() + 1);
document.cookie = ''password=
EWEBIAC_HTML_LOGIN_FIELDS-alias_name_RES.value; path= /'';
document.cookie = ''user=
EWEBIAC_HTML_LOGIN_FIELDS-PASS_RES.value; expires='' +
nextyear.toGMTString() +''; path= /'';
}
savecookie();
</script>
Now, it''s almost working. It does save the cookie for me, but the
values are all messed up. I think I have a syntax error in assigning
the cookie variables. I''m hoping it''s just a few quotation marks or
something that someone here can identify for me. I assign the variables
like this because of how the SAP looks below:
<body `SAP_BodyAttributes()` onLoad="`SAP_OnLoadJavaScript()`">
`SAP_TemplateFormBegin()`
<h2 style="font-style:arial" style="font-size:24pt">`#l_header`</h2>
`SAP_TemplateGroupBoxBegin( groupboxlabel=#success)`
`SAP_TemplateInfoLine(~messageline)`
<br>
`SAP_TemplateNonEditableField("alias_name_RES",
fieldLabel=fieldLabel=#alias_name,
fieldLabelWidth="250",value=EWEBIAC_HTML_LOGIN_FIE LDS-alias_name_RES.value,size="150")`
<br>
`SAP_TemplateNonEditableField("PASS_RES",
fieldLabel=EWEBIAC_HTML_LOGIN_FIELDS-PASS_RES.label,
fieldLabelWidth="250",value=EWEBIAC_HTML_LOGIN_FIE LDS-PASS_RES.value,size="20")`
<br>
`SAP_TemplateNonEditableField("smtp",
fieldLabel=EWEBIAC_HTML_LOGIN_FIELDS-smtp.label,
fieldLabelWidth="250",value=EWEBIAC_HTML_LOGIN_FIE LDS-smtp.value,size="100")`
<script language="JavaScript">
savecookie();
</script>
.....
<snip>
anyone have an idea of how I can get the variables passed from the
previous form into the cookie? Thanks!
<11**********************@f14g2000cwb.googlegroups .com>
var passwd = document.forms[''MyFormName''].
elements[''EWEBIAC_HTML_LOGIN_FIELDS-alias_name_RES''].value;
// JavaScript doesn''t resolve variables inside strings, it''s not Perl
here :-)
// And what an ugly name with *minus* in it which is always a call for
troubles :-(
// But it''s your solution anyway...
document.cookie = ''password='' + escape(passwd) +''; path= /'';
// cookie values need to be escaped (es well as cookie names
// if you use some strange chars in it which is not a case here)
And so on with other cookies...
VK wrote:<11**********************@f14g2000cwb.googlegroups .com>
var passwd = document.forms[''MyFormName''].
elements[''EWEBIAC_HTML_LOGIN_FIELDS-alias_name_RES''].value;
// JavaScript doesn''t resolve variables inside strings, it''s not Perl
here :-)
// And what an ugly name with *minus* in it which is always a call for
troubles :-(
// But it''s your solution anyway...
document.cookie = ''password='' + escape(passwd) +''; path= /'';
// cookie values need to be escaped (es well as cookie names
// if you use some strange chars in it which is not a case here)
And so on with other cookies...
Thank you friend, and if this works, I''ll put those comments in there
just for fun :)
VK wrote:
<11**********************@f14g2000cwb.googlegroups .com>
You are trolling.
[...]
document.cookie = ''password='' + escape(passwd) +''; path= /'';
// cookie values need to be escaped (es well as cookie names
// if you use some strange chars in it which is not a case here)
Nonsense. `passwd'' only needs to be escaped if it contained a
`;'' as this is already the cookie value component delimiter;
a simple passwd.replace(";", "%3B") suffices.
PointedEars
这篇关于自动登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!