Page 1 of 1

need help with 2 niggling problems

Posted: Tue Nov 18, 2003 1:09 pm
by malcolmboston
ok guys, i need some help on 2 really annoying problems i am having, any help would be much appreciated

problem 1
windows remembering what your username and password is when you start typing it out (windows autocomplete)

ok what i would like to 'achieve' is, like on the msn site, the "this is a shared computer, do not remember my password in the future" as the site i am currently building needs to be quite secure and i believe adding this will make it more secure, could anyone help me out with this as i cant seem to find any topics about this which i dont believe is the case

Problem 2
Ok, when somebody logs in i would like it to say there username
Kinda like "Welcome Back John Smith" now i cannot seem to figure out how this is done, i (obviously) know how to add dynamic text from mysql and access very easily but i believe this must be done in some other way or with filtering options set to something (possibly from a recordset or the session) but if someone could help me out with this i would be extremely grateful

i started out using ASP and quickly changed to PHP and have picked it up extremely quicky imho, ASP sucked, and i have managed to do alot with PHP, never had any login scruipt problems which alot of people seem to have but this i have no idea where to start from

A troubled web-developer awaiting a reply :)

Posted: Tue Nov 18, 2003 1:14 pm
by m3mn0n
Try using either cookiesor sessionsto manage user accounts.

Once you understand those two concepts, anything in that regard is quite simple.

[big_search]php user management tutorials[/big_search]

Posted: Tue Nov 18, 2003 1:22 pm
by malcolmboston
lol ok

so technically if i do something along the lines of

msession_get
or
session_name
then it should work?

hmmmm god im confused,, surely that would only give me back the session value like 7467645823764876 etc loads of numbers!

hmmmm, me thinks i need more help lol
sorry guys

Posted: Tue Nov 18, 2003 1:23 pm
by microthick
For problem #1, look here:
http://msdn.microsoft.com/library/defau ... /acoff.asp

You can turn off a form field's autocomplete ability by using the attribute autocomplete:

<form method=post action="something.php" autocomplete="off">

Or

<input type="text" name="creditcard" value="" size="16" maxlength="16" autocomplete="off">

Or using JavaScript. See link for code.

Posted: Tue Nov 18, 2003 1:25 pm
by malcolmboston
THANK YOU!!!

finally, thats one problem solved and its working correctly, seems strange ive never heard of that as a HTML attribute :oops:

Thanks alot

This forum is great hehe

Posted: Tue Nov 18, 2003 1:32 pm
by d3ad1ysp0rk
don't worry, neither have i..
i guessed it's not a widely known/used attribute

btw, what browsers support it?

Posted: Tue Nov 18, 2003 1:32 pm
by m3mn0n

Code: Select all

<?php
$username = "John Doe";

setcookie("usernamecookie",$username,time()+3600); // for 1 hour

?>
then to retrive it....

Code: Select all

<?php
// also 
// $your_username = $_COOKIE['usernamecookie']; 
// if your settings are right
$your_username = $HTTP_COOKIE_VARS["usernamecookie"];

if ($your_username != "")
{
   echo "Hello, ".$your_username."! Welcome back.";
} else {
   echo "<br>";
}
?>
just a tiny example....more info at the links i posted.

Posted: Tue Nov 18, 2003 1:41 pm
by malcolmboston
ok

listen im sorry, as i said im still pretty new to PHP and i have read (and downloaded for viewing off-line) the 2 links you provided

ok the example you provided
<?php
$username = "John Doe";

setcookie("usernamecookie",$username,time()+3600); // for 1 hour

?>
see the username tag/attribute whatever you wanna call it, hmm im assuming because you have written John Doe in it, that that is a preset value right? now forgive me if im completely wrong :roll:

ok so how do i get it to show up as the value that was inserted on username input button
for eg
Username = John Smith
Password = ******

on the next page it would be Welcome Back John Smith, ok, well ive tried to explain it to the best of my ability, but basically to cut a long story short how do i make it a variable instead of a preset name?

Forgive me for my n00biness, just eager to learn :D
btw what browsers does it support
i should imagine, seeing as it is done by windows, it should technically disable it as long as you are running on a windows box (gonna try it on RH9 when i get home, ill post back with the answer)

Posted: Tue Nov 18, 2003 1:46 pm
by m3mn0n
You're right about it's value.

To make it something from a post variable, simply replace the set "John Doe" value with something like trim($_POST["username"]).

Code: Select all

<?php
// trim() removes useless spaces
//$_POST array retreives POST'ed data
$username = trim($_POST["username"]); // username is the value of the textfield
?>
eg.

Code: Select all

&lt;input type="text" name="username" value=""&gt;

Posted: Tue Nov 18, 2003 1:52 pm
by malcolmboston
Thank You Sami

im ognna go away now and start trying out what you have told me, you only learn by trying and testing, if i need anymore help ill be sure to be back on here

i would just like to say how helpful you guys have been especially sami, this is the reason why PHP is the best, a great community (unlike asp, who hate newcomers :twisted:

Thanks Again Guys
<--- New addition to the community

Posted: Tue Nov 18, 2003 2:00 pm
by m3mn0n
hehe no problemo. Welcome to the community.

I'm not one to simply say "RTFM," and that's it. I help as I would like to be helped in the opposite side of the situation. :) (Plus it's a rule here, hehe)

Posted: Wed Nov 19, 2003 10:51 am
by malcolmboston
ok well i tried it out last night this is what happened.

i put in the code as you written it and it didnt seem to work, after messing around with it for a while it suddenly worked (once) so after celebrating my achievement and sitting down and watching a film for some much needed chill out time, i went back and it no longer worked

also when checking my cookie folder only one was there!? when technically there should of been more than that because i had logged in as different users several times (also it kept on echoing the same variable even though i was loggin in aqs different names, this leads me to believe that it was continiously using the same cookie even though i had specified a new username!?

Im confused as to why it wont work anymore, does anyone know a fail-safe snippet of code or at least on that i php newcomer can understand (well commented)

Thank You