This topic is locked
[SOLVED]

 Username as default value from variable

10/1/2010 9:32:50 AM
PHPRunner General questions
S
stenac author

Hi all,
just a question from a newbie like me. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=15359&image=1&table=forumtopics' class='bbc_emoticon' alt=':rolleyes:' />
To avoid LDAP authentication for my intranet, I used an external file created with kixtart to read a field with the Active Directory username; i put this value in a php variable called $uName.

I can read/print this value on login page creating a BeforeProcessLogin function like this (I rewrite some parts of code, so i don't know if this script really works):
function BeforeProcessLogin($conn)

{

$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);

$file = fopen("$hostname.txt","r");

$filecontent = fread($file, 100);

echo "this is your network username: $filecontent";

$uName=$filecontent;

fclose ($file);

}
Now... I want to write the $uName value in the username editbox (i assume password field as blank value) so my users have only to click button to authenticate to the intranet with their privileges.
In other words... I want to write $uName value on username editbox in login page.
How can I do this??
I read on forum how put a default value on add or edit page, but not on login page.
Thanks.
Stefano ;o)

Admin 10/1/2010

Since you are not planning to have a password I recommend to save your users one click and logon them automatically.
You'll need to populate session variables $_SESSION["UserID"] and $_SESSION["AccessLevel"] and then redirect user to another page.

Here is an example of how you can do this:

http://xlinesoft.com/phprunner/docs/implementing_single_sign_on.htm

S
stenac author 10/4/2010

ok... thanks.

But i thought was simpler than your solution.

I wanted to know if it's possible to automatically write in the login page in the username field, my variable value.

I saw php code of login.php and html code of /templates/login.html and I need to edit this line
<input name=username {$username_attrs}>
like this: <input name=username value=<?php echo $UNAME; ?> {$username_attrs}>
but this obviously doesn'work.
maybe I have to change login.php to see /templates/login.PHP instead .htm and try to write value in php mode.
Any suggestion?

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=53205&image=1&table=forumreplies' class='bbc_emoticon' alt=':unsure:' />

Admin 10/4/2010

You can use the following in BeforeProcess event of the login page:

$xt->assign("username_attrs", " value='" . $_SESSION["UserID"] . "' ");
S
stenac author 10/5/2010

OK... now it's ok, but i didn't use login BeforeProcess event.

I've modified the following lines in LOGIN.PHP file:
**ORIGINAL****

if(postvalue("username"))

$xt->assign("username_attrs",($is508==true ? "id=\"username\" " : "")."value=\"".htmlspecialchars($pUsername)."\"");

else

$xt->assign("username_attrs",($is508==true ? "id=\"username\" " : "")."value=\"".htmlspecialchars(refine(@$_COOKIE["username"]))."\"");

**
in
**MODIFIED****

if(postvalue("username"))

$xt->assign("username_attrs", " value='".$_SESSION["UserID"] . "' ");

else

$xt->assign("username_attrs", " value='".$_SESSION["UserID"] . "' ");

**
Thanks a lot for your help.
Stefano <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=53263&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' /> <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=53263&image=2&table=forumreplies' class='bbc_emoticon' alt=':D' /> <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=53263&image=3&table=forumreplies' class='bbc_emoticon' alt=':D' /> <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=53263&image=4&table=forumreplies' class='bbc_emoticon' alt=':D' />