PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old July 29th, 2002, 09:56 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
User authorization

Hello,

This is a question regarding user authorization.
I've set of files in my directory and i want to put up a log in screen to enter the user name and password to view any files in the working directory.well, i made it so!
Index.php is my screen for log-in details.

when the user is logged in successfully,main.php will be shown.Now, my question is, when the user tries to view main.php or any other php files in my directory,it should pop up my log-in screen that is index.php.How can i do this?

This is the code which i used for index.php.

<?php
$myuser = "admin";
$mypass = "pass";

if ($user == $myuser && $pass == $mypass)

{
header ('location: main.php');

}

else
{
echo"<form action="$PHP_SELF" method="POST">n";


}

?>

-----Here follows my HTML code for screen display------
Thank you

Reply With Quote
  #2  
Old July 29th, 2002, 10:12 AM
D1NGO D1NGO is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Perth, Australia
Posts: 221 D1NGO User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: User authorization

what you should do is, when they type in the correct login info, set a cookie on their system, then if they try to go to another page, run a script that asks if the cookie is there, if not, then display the login screen

hope thats some help

Reply With Quote
  #3  
Old July 29th, 2002, 10:25 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: User authorization

Ne other suggestions other than setting cookies?

Reply With Quote
  #4  
Old July 29th, 2002, 10:45 AM
D1NGO D1NGO is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Perth, Australia
Posts: 221 D1NGO User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: User authorization

if you dont wanna use cookies, you could always use sessions instead

Reply With Quote
  #5  
Old July 29th, 2002, 12:41 PM
siteworkspro.com siteworkspro.com is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Sydney, Australia
Posts: 92 siteworkspro.com User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to siteworkspro.com Send a message via AIM to siteworkspro.com
RE: User authorization

try reading this article on restricting access to files via .htaccess files.
http://www.devarticles.com/art/1/15

Reply With Quote
  #6  
Old July 29th, 2002, 12:42 PM
Gunblade Gunblade is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: England
Posts: 31 Gunblade User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Gunblade Send a message via AIM to Gunblade Send a message via Yahoo to Gunblade
RE: User authorization

<?php
//this uses sessions - see the php manual if you are confused on this part
session_start(); //start session
//see the php manual for the reasons on the SID part
?>
<html>
<head>
</head>
<body>
\file.php should be the file that
\checks if the username and password
\ are correct
<form method="POST" action="file.php">

<?
//setting the error messages to match the type of error

//this message is if no username/password pair is entered
if ($error==1){
echo "<font color="#FF0000" face="arial" size="2">";
echo "Invalid Login - Please try again";
echo "</font>";
echo "<br>";
session_destroy();
}
//this message is if the wrong username/password pair is entered
if ($error==2){
echo "<font color="#FF0000" face="arial" size="2">";
echo "Unauthorized Access - Please Login";
echo "</font>";
echo "<br>";
session_destroy();
}

//this message is if the cookie has expired
if ($error==3){
echo "<font color="#FF0000" face="arial" size="2">";
echo "Session has expired - Please Login";
echo "</font>";
echo "<br>";
session_destroy();
}

//setting the form now for input
?>
name:<br>
<input type="text" name="username" size="20">
<br>
password:
<br>
<input type="password" name="password" size="20">
<br>
<input type="submit" value="Submit" name="B1">
<br>
<input type="reset" value="Reset" name="B2">
</form>
</body>
</html>

Reply With Quote
  #7  
Old July 29th, 2002, 01:01 PM
ASk ASk is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 12 ASk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: User authorization

if you plan on using it for multiple users, you should implement uniqid(rand(), 1) to assign each user the uniqid and storing its MD5 in the cookie.

(This happened to me, when my cookies were too easy to forge. This method makes it substantially harder)

Reply With Quote
  #8  
Old July 30th, 2002, 02:32 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: User authorization

Hello,

can some body help me in modifying my code little bit.
I'm trying to put up a log-in screen, the user name and password is hardcode.If the user does'nt enter the login details and press submit, it should check for error 1 and if the login details are not correct it should check for error 2.
Hope somebody would help me.

thank you

<?php
session_start();
?>

<?php
$myuser = "admin";
$mypass = "pass";

if ($user == $myuser && $pass == $mypass)

{
header ('location: main.php');

}

else
{
echo"<form action="$PHP_SELF" method="POST">n";

}
?>

<?

//To check if no user name and password is entered.
if ($error==1){
echo "<font color="#FF0000" face="vendana" size="2">";
echo "Invalid Login - Please try again";
echo "</font>";
echo "<br>";
session_destroy();
}

//To check if user name and password entered is wrong

if ($error==2){
echo "<font color="#FF0000" face="vendana" size="2">";
echo "Unauthorized Access - Please Login";
echo "</font>";
echo "<br>";
session_destroy();
}

//To set the form for input

?>
Herez my html code which displays the log-in screen.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > User authorization


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway