•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 403,396 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,700 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 462 | Replies: 7 | Solved
![]() |
•
•
Join Date: Jan 2008
Posts: 55
Reputation:
Rep Power: 1
Solved Threads: 5
•
•
•
•
My idea is to store username and password in a php file and update them.
I'm not sure if this would be the best way to do it...
However, the basic functions you'll need to use are PHP's file functions. The simplest way to do it would be...
php Syntax (Toggle Plain Text)
$fileContents = file_get_contents($filename); // Do something with the contents file_put_contents($filename, $newFileContents);
file_get_contents() takes a filename (string) and returns the contents of the file in a string.
file_put_contents takes a filename (string) and contents (string) and writes them to the file.
For storing usernames and passwords, the best solution is probably to use a mysql database. You could read the databases section of Practical PHP Programming for an overview of mysql and the related php functions.
Another option would be to use an xml file to store the usernames and the hashed passwords (after they've been processed with md5 or crypt). This is a simpler option if you don't have access to or don't want to use a database.
PHP has some great built in functionality with xml now using SimpleXML. You could read the SimpleXML section of Practical PHP Programming for an overview on how to use it to read, write, and modify xml data.
Good luck,
- Walkere
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 239
•
•
•
•
'm not sure if this would be the best way to do it...
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Jul 2007
Posts: 14
Reputation:
Rep Power: 2
Solved Threads: 0
I solved my problem like this..
changepwd.php
strings.php
changepwd.php
include("strings.php");
$checkpass=$pass;
$newpass=$_REQUEST['NewPwd'];
$fn = "strings.php";
$file = fopen($fn, "w+");
$size = filesize($fn);
fwrite($file, "<?php "."$"."pass='".$newpass."';?>");
fclose($file);
echo "Password changed successfully";strings.php
<?php $pass='venkat';?>
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 239
Glad that you solved your problem. But still it isnt safe
Anyways, All the best!
Anyways, All the best! Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Jan 2008
Posts: 55
Reputation:
Rep Power: 1
Solved Threads: 5
•
•
•
•
Glad that you solved your problem. But still it isnt safeAnyways, All the best!
Should be plenty safe. No one will be able to see the password details, because it will be parsed by the php interpreter. Just like how your mySQL user/password information is floating around somewhere in a config.php file...
Are you just saving one password in there? Or are there more users?
- Walkere
•
•
Join Date: Jan 2008
Posts: 55
Reputation:
Rep Power: 1
Solved Threads: 5
Ahh, I thought that you were going to store a bunch (or at least a handful of users).
If you tried to add more records to the file, it would get more complicated to parse the variable names, make sure you didn't use the same name twice, etc.
But for one user, I suppose it's simple enough. Definitely a strange way to do it, but if it works, who cares? Kudos for thinking outside the box.
- Walkere
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Updated : Simple ASP.Net Login Page (ASP.NET)
- problem with login page (C#)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
- Error message when running ASP login page (ASP)
Other Threads in the PHP Forum
- Previous Thread: quickie
- Next Thread: dynamic drop down menu in php



Linear Mode