This topic is locked

Link For Default Login

9/14/2005 10:55:24 AM
PHPRunner General questions
pplaut author

Hey,

I would like to have a direct link on my web site to take users to a "demo" login where I would not have to have them login with a userid and password.
I saw where you could do it with guest, but what about "demo"
Thanks

Peer

Admin 9/15/2005

Peer,
to pass username and password to login.php please do the following:
Open login.php in a text editor and replace all occurences of

$_POST with $_REQUEST.

Then you can use the following URL to get to your pages.

http://..../login.php?btnSubmit=Login&username=demo&password=demopass



where demo and demopass are your actual username and password.

pplaut author 9/15/2005

Will this break the normal login process for regualr users?

Peer

Admin 9/15/2005

No, regular users won't see any change.

pplaut author 9/18/2005

Below this line is the url you sent me.

http://trackerplus.net/trackerplus/login.php?
btnSubmit=Login&username=demo&password=demopassword
Whenever I run it I get returned to the login page....

I can login manually with these credentials.
Below is the login.php script. Thanks for your help on this.
<?php

ini_set("display_errors","1");

ini_set("display_startup_errors","1");

session_start();

if(!@$_SESSION["MyURL"])

session_unset();

set_magic_quotes_runtime(0);
include("include/dbcommon.php");

include("include/dbconnection.php");
$myurl=@$_SESSION["MyURL"];

unset($_SESSION["MyURL"]);
$cLoginMethod = 1;

$cUserName = "";

$cPassword = "";

$cAdminUserID = "admin";
$strMessage="";
if (@$_REQUEST["lang"])

{

$_SESSION["language"]=@$_REQUEST["lang"];

}
if (@$_REQUEST["btnSubmit"] == "Login")

{

if(@$_REQUEST["remember_password"] == 1)

{

setcookie("username",@$_REQUEST["username"],time()+365144060);

setcookie("password",@$_REQUEST["password"],time()+365144060);

$strChecked = " checked";

}

else

{

setcookie("username","",time()-365144060);

setcookie("password","",time()-365144060);

$strChecked = "";

}

if($cLoginMethod == LOGIN_HARDCODED)

{

// username and password are hardcoded

if(!strcmp($cPassword, @$_REQUEST["password"]) && !strcmp($cUserName, @$_REQUEST["username"]))

{

$_SESSION["UserID"] = $_REQUEST["username"];

$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;

if($myurl)

header("Location: ".$myurl);

else

header("Location: ".str_replace(" ","%20","menu.php"));

return;

}

else

{

$strMessage = "Invalid Login";

session_unset();

}

}

else

{

// username and password are stored in the database

$conn=db_connect();

$strUsername = (string)@$_REQUEST["username"];

$strPassword = (string)@$_REQUEST["password"];
$rstemp=db_query("select from ".AddTableWrappers($cLoginTable)." where 1=0",$conn);
if(NeedQuotes(db_fieldtype($rstemp,$cUserNameField)))

$strUsername="'".db_addslashes($strUsername)."'";

else

$strUsername=(0+$strUsername);

if(NeedQuotes(db_fieldtype($rstemp,$cPasswordField)))

$strPassword="'".db_addslashes($strPassword)."'";

else

$strPassword=(0+$strPassword);
$strSQL = "select
from ".AddTableWrappers($cLoginTable)." where ".AddFieldWrappers($cUserNameField).

"=".$strUsername." and ".AddFieldWrappers($cPasswordField).

"=".$strPassword;

$rs=db_query($strSQL,$conn);
if($data=db_fetch_array($rs))

{

$_SESSION["UserID"] = @$_REQUEST["username"];

$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;

if($_REQUEST["username"]==$cAdminUserID)

$_SESSION["AccessLevel"] = ACCESS_LEVEL_ADMIN;

if(strlen("user_id"))

$_SESSION["OwnerID"] = $data["user_id"];

if($myurl)

header("Location: ".$myurl);

else

header("Location: ".str_replace(" ","%20","menu.php"));

return;

}

else

{

$strMessage = "Invalid Login";

session_unset();

}

}

}

else

$strChecked = " checked";
if($myurl)

$_SESSION["MyURL"]=$myurl;
if(@$_REQUEST["username"])

$strUsername = $_REQUEST["username"];

else

$strUsername = @$_COOKIE["username"];
if(@$_REQUEST["password"])

$strPassword = $_REQUEST["password"];

else

{

$strPassword = @$_COOKIE["password"];

$strPassword = "";

}
if(@$_GET["message"]=="expired")

$strMessage = "Your session has expired. Please login again.";
?>

<html>

<head>

<title>Login</title>

<link REL="stylesheet" href="include/style.css" type="text/css">

</head>
<script language = JavaScript>
function OnKeyDown()

{

e = window.event;

if (e.keyCode == 13)

{

e.cancel = true;

document.forms[0].submit();

}

}

</script>
<body bgcolor=white onLoad="java script:document.forms[0].username.focus();document.forms[0].password.onkeydown = OnKeyDown;" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#0066cc">

<?php

if(file_exists("include/supertop.php"))

include("include/supertop.php");

?>

<table width="100%" border="0" cellspacing="0" cellpadding="0" height="99%">

<tr>

<td valign="center" align="middle">

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td>&nbsp;</td>

</tr>

</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td bgcolor="#ffffff" valign="top" align="right">

<table width="300" border="0" cellspacing="4" cellpadding="4" align="center">

<tr>

<td>&nbsp;</td>

</tr>

</table>

<form method="POST" action="login.php" id=form1 name=form1>

<table width="300" border="0" cellspacing="1" cellpadding="4" align="center" bgcolor="#cccccc">

<tr>

<td align=middle class=blackshade>

<b><font size=+1>Login</font></b></td>

</tr>

<tr>

<td valign="top" class=shade>

<DIV align=center>

<table width="200" border=0 align="center" class=shade>

<tbody>

<tr height=10><td colspan=2>&nbsp;</td></tr>

<tr>

<td align=right width="50%">

<div align="left">Username:</div>

</td>

<td width="50%">

<input name=username value="<?php echo htmlspecialchars($strUsername);?>">

</td>

</tr>

<tr>

<td align=right width="50%">

<div align="left">Password:</div>

</td>

<td width="50%">

<input type=password name=password value="<?php echo htmlspecialchars($strPassword);?>">

</td>

</tr>
<tr>

<td align=right width="50%">

<div align="left">Remember Password::</div>

</td>

<td width="50%">

<input type=checkbox name=remember_password value="1" <?php echo $strChecked;?>>

</td>

</tr>

<tr>

<td colspan=2 align=middle>

<input type=hidden name=btnSubmit value="Login">

<input type=submit value="Submit" class=buttonM>

</td>

</tr>
<tr>

<td colspan=2 align=middle>

<a href="register.php">Register</a>

<a href="remind.php">Forgot password?</a>

</td>

</tr>
<tr height=20>

<td align=center colspan=2>

<font color=red><?php echo $strMessage;?></font>&nbsp;

</td></tr>
</tbody>

</table></DIV>

</td>

</tr>

</table>

</form>

<p>&nbsp;</p></td>

</tr>

</table>
</td>

</tr>

</table>

</td>

</tr>

</table>

<?php

if(file_exists("include/superbottom.php"))

include("include/superbottom.php");

?>

</body>

</html>

<?php
?>

pplaut author 9/18/2005

I dunno what I did, but things got way worse, so I too a close look at the script and started taking out blank lines................ viola........... it started working.

Go figure!

Thanks

Peer

pplaut author 10/7/2005

I seem to still be having intermittent problems with this auto login.

Here is the login.php

To see what happens...

www.trackerplus.net click on the Demo

Thanks

Peer
<?php

ini_set("display_errors","1");

ini_set("display_startup_errors","1");

session_start();

if(!@$_SESSION["MyURL"])

session_unset();

set_magic_quotes_runtime(0);
include("include/dbcommon.php");

include("include/dbconnection.php");
$myurl=@$_SESSION["MyURL"];

unset($_SESSION["MyURL"]);
$cLoginMethod = 1;

$cUserName = "";

$cPassword = "";

$cAdminUserID = "admin";
$strMessage="";
if (@$_REQUEST["lang"])

{

$_SESSION["language"]=@$_REQUEST["lang"];

}
if (@$_REQUEST["btnSubmit"] == "Login")

{

if(@$_REQUEST["remember_password"] == 1)

{

setcookie("username",@$_REQUEST["username"],time()+365144060);

setcookie("password",@$_REQUEST["password"],time()+365144060);

$strChecked = " checked";

}

else

{

setcookie("username","",time()-365144060);

setcookie("password","",time()-365144060);

$strChecked = "";

}

if($cLoginMethod == LOGIN_HARDCODED)

{

// username and password are hardcoded

if(!strcmp($cPassword, @$_REQUEST["password"]) && !strcmp($cUserName, @$_REQUEST["username"]))

{

$_SESSION["UserID"] = $_REQUEST["username"];

$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;

if($myurl)

header("Location: ".$myurl);

else

header("Location: ".str_replace(" ","%20","menu.php"));

return;

}

else

{

$strMessage = "Invalid Login";

session_unset();

}

}

else

{

// username and password are stored in the database

$conn=db_connect();

$strUsername = (string)@$_REQUEST["username"];

$strPassword = (string)@$_REQUEST["password"];
$rstemp=db_query("select from ".AddTableWrappers($cLoginTable)." where 1=0",$conn);
if(NeedQuotes(db_fieldtype($rstemp,$cUserNameField)))

$strUsername="'".db_addslashes($strUsername)."'";

else

$strUsername=(0+$strUsername);

if(NeedQuotes(db_fieldtype($rstemp,$cPasswordField)))

$strPassword="'".db_addslashes($strPassword)."'";

else

$strPassword=(0+$strPassword);
$strSQL = "select
from ".AddTableWrappers($cLoginTable)." where ".AddFieldWrappers($cUserNameField).

"=".$strUsername." and ".AddFieldWrappers($cPasswordField).

"=".$strPassword;

$rs=db_query($strSQL,$conn);
if($data=db_fetch_array($rs))

{

$_SESSION["UserID"] = @$_REQUEST["username"];

$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;

if($_REQUEST["username"]==$cAdminUserID)

$_SESSION["AccessLevel"] = ACCESS_LEVEL_ADMIN;

if(strlen("user_id"))

$_SESSION["OwnerID"] = $data["user_id"];

if($myurl)

header("Location: ".$myurl);

else

header("Location: ".str_replace(" ","%20","menu.php"));

return;

}

else

{

$strMessage = "Invalid Login";

session_unset();

}

}

}

else

$strChecked = " checked";
if($myurl)

$_SESSION["MyURL"]=$myurl;
if(@$_REQUEST["username"])

$strUsername = $_REQUEST["username"];

else

$strUsername = @$_COOKIE["username"];
if(@$_REQUEST["password"])

$strPassword = $_REQUEST["password"];

else

{

$strPassword = @$_COOKIE["password"];

$strPassword = "";

}
if(@$_GET["message"]=="expired")

$strMessage = "Your session has expired. Please login again.";
?>

<html>

<head>

<title>Login</title>

<link REL="stylesheet" href="include/style.css" type="text/css">

</head>
<script language = JavaScript>
function OnKeyDown()

{

e = window.event;

if (e.keyCode == 13)

{

e.cancel = true;

document.forms[0].submit();

}

}

</script>
<body bgcolor=white onLoad="java script:document.forms[0].username.focus();document.forms[0].password.onkeydown = OnKeyDown;" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#0066cc">

<?php

if(file_exists("include/supertop.php"))

include("include/supertop.php");

?>

<table width="100%" border="0" cellspacing="0" cellpadding="0" height="99%">

<tr>

<td valign="center" align="middle">

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td>&nbsp;</td>

</tr>

</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td bgcolor="#ffffff" valign="top" align="right">

<table width="300" border="0" cellspacing="4" cellpadding="4" align="center">

<tr>

<td>&nbsp;</td>

</tr>

</table>

<form method="POST" action="login.php" id=form1 name=form1>

<table width="300" border="0" cellspacing="1" cellpadding="4" align="center" bgcolor="#cccccc">

<tr>

<td align=middle class=blackshade>

<b><font size=+1>Login</font></b></td>

</tr>

<tr>

<td valign="top" class=shade>

<DIV align=center>

<table width="200" border=0 align="center" class=shade>

<tbody>

<tr height=10><td colspan=2>&nbsp;</td></tr>

<tr>

<td align=right width="50%">

<div align="left">Username:</div>

</td>

<td width="50%">

<input name=username value="<?php echo htmlspecialchars($strUsername);?>">

</td>

</tr>

<tr>

<td align=right width="50%">

<div align="left">Password:</div>

</td>

<td width="50%">

<input type=password name=password value="<?php echo htmlspecialchars($strPassword);?>">

</td>

</tr>
<tr>

<td align=right width="50%">

<div align="left">Remember Password::</div>

</td>

<td width="50%">

<input type=checkbox name=remember_password value="1" <?php echo $strChecked;?>>

</td>

</tr>

<tr>

<td colspan=2 align=middle>

<input type=hidden name=btnSubmit value="Login">

<input type=submit value="Submit" class=buttonM>

</td>

</tr>
<tr>

<td colspan=2 align=middle>

<a href="register.php">Register</a>

<a href="remind.php">Forgot password?</a>

</td>

</tr>
<tr height=20>

<td align=center colspan=2>

<font color=red><?php echo $strMessage;?></font>&nbsp;

</td></tr>
</tbody>

</table></DIV>

</td>

</tr>

</table>

</form>

<p>&nbsp;</p></td>

</tr>

</table>
</td>

</tr>

</table>

</td>

</tr>

</table>

<?php

if(file_exists("include/superbottom.php"))

include("include/superbottom.php");

?>

</body>

</html>

<?php
?>

Admin 10/10/2005

Peer,
autologin works fine in your example. What is the problem?

pplaut author 10/10/2005

OK,

I am not sure what is going on.

If you go to trackerplus.net and click on the demo link.

The first time, it comes up with a userid and password request.

The second time, it comes up properly logged in.

Do you get the same results?

Peer