Forum Moderators: open

Message Too Old, No Replies

javascript set cookie reload page from form

         

realitybytesuk

9:40 am on Apr 8, 2005 (gmt 0)

10+ Year Member



Any javascript help would be greatly appreciated!

Here is the last code I tried running.

<form name = "login" action="<?=$_SERVER['PHP_SELF']?>" method="post">
&nbsp;<span class=txtNr><b>&raquo;</b></span>&nbsp;Name&nbsp;<input type=text size=10 maxlength=40 name="authName" class=textForm>
<span class=txtNr><b>&raquo;</b></span>&nbsp;<a href="http://localhost/forums/index.php?action=sendpass">Password</a>&nbsp;<input type=password size=10 maxlength=32 name="authPass" class=textForm>
<input type="submit" name="login" ONCLICK = "login()" class="imputbutton" value="Login">
</form>

<script language="Java Script" type="text/javascript">
function login() {
var username = document.login.authName
var userpass = md5(document.login.authPass)
var cookdate = new Date()
cookdate.seTime(cookdate.getTime()
+1000*60*30)
document.cookie = "forumcookie="+(username)¦(userpass)¦+"1113049725;expires="+cookdate.toGMTSTRING()";+path=/"
}

The idea is that once the form is submitted it sets the authName and authPass (authPass needs to be md5) fields in a cookie, the page needs to be reloaded as that is when the authentication takes place providing the cookie is set I used PHP_SELF, however I am not sure if this is correct with javascript and maybe javascript is reqiuired to reload the page. The path needs to be set to / so the forum will accept the same cookie.

After days of reading up on PHP, I cannot seem to get my head around the javascript syntax. I had the form post the results originally and then used PHP require array above the headers to setcookie but this needed a page refresh before the page authentication would detect the cookie, and because the setcookie is present I am unable to use header() to reload.

Time for sleep for me anyway, if anybody posts a solution before I crack this it will be greatly appreciated.

realitybytesuk

12:28 pm on Apr 8, 2005 (gmt 0)

10+ Year Member



Alternatively is there any way I am able to make the browser reload, when having this as the form

<a href="http://localhost/Auth/functions_test_2.php">link</a>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
&nbsp;<span class=txtNr><b>&raquo;</b></span>&nbsp;Name&nbsp;<input type=text size=10 maxlength=40 name="authName" class=textForm>
<span class=txtNr><b>&raquo;</b></span>&nbsp;<a href="http://localhost/forums/index.php?action=sendpass">Password</a>&nbsp;<input type=password size=10 maxlength=32 name="authPass" class=textForm>
<input type="submit" name="login" class="imputbutton" value="Login">
</form>

The following is above the headers which sets the cookie fine but requires a reload for the auth to detect the cookie

<?php
if (isset($_POST['login'])) {
$authName = $_POST['authName'];
$authPass = md5($_POST['authPass']);
setcookie('forumcookie', $authName.'¦'.$authPass.'¦'.'1113049725', time()+108000, '/', '', 0);
}
?>

realitybytesuk

3:15 pm on Apr 8, 2005 (gmt 0)

10+ Year Member



Ok not to worry I have found a work around, authenticate with the database then pass a auth variable along to bypass the first authentication sequence.