User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jul 2007
Posts: 14
Reputation: creativehacker is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
creativehacker creativehacker is offline Offline
Newbie Poster

Help Login page login help

  #1  
Feb 2nd, 2008
Hi
I want to create a login screen which asks for username and passwor with change passsword facility.

My idea is to store username and password in a php file and update them.

Can anyone please tell me how to update a php file from another php file..


Thanx in advance
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Posts: 55
Reputation: Walkere is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
Walkere Walkere is offline Offline
Junior Poster in Training

Re: Login page login help

  #2  
Feb 2nd, 2008
Originally Posted by creativehacker View Post
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...

  1. $fileContents = file_get_contents($filename);
  2.  
  3. // Do something with the contents
  4.  
  5. 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
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Login page login help

  #3  
Feb 2nd, 2008
'm not sure if this would be the best way to do it...
Exactly. Its not the best way. Its not safe. And, btw, file_put_contents only works if your php version is >= 5. Even I suggest you to use mysql database. But, if you can't have a database, then you can use a text file(or xml) as a 'database'.
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*
Reply With Quote  
Join Date: Jul 2007
Posts: 14
Reputation: creativehacker is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
creativehacker creativehacker is offline Offline
Newbie Poster

Re: Login page login help

  #4  
Feb 2nd, 2008
I solved my problem like this..


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';?>
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Login page login help

  #5  
Feb 3rd, 2008
Glad that you solved your problem. But still it isnt safe 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*
Reply With Quote  
Join Date: Jan 2008
Posts: 55
Reputation: Walkere is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
Walkere Walkere is offline Offline
Junior Poster in Training

Re: Login page login help

  #6  
Feb 3rd, 2008
Originally Posted by nav33n View Post
Glad that you solved your problem. But still it isnt safe Anyways, 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
Reply With Quote  
Join Date: Jul 2007
Posts: 14
Reputation: creativehacker is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
creativehacker creativehacker is offline Offline
Newbie Poster

Re: Login page login help

  #7  
Feb 3rd, 2008
There will be only one user...
So that worked for me
Reply With Quote  
Join Date: Jan 2008
Posts: 55
Reputation: Walkere is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
Walkere Walkere is offline Offline
Junior Poster in Training

Re: Login page login help

  #8  
Feb 3rd, 2008
Originally Posted by creativehacker View Post
There will be only one user...
So that worked for me


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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:40 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC