Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Session Password verification

Status
Not open for further replies.

tiamat2012

Programmer
Dec 12, 2004
144
US
Hey all,

For my clients I create little sections where they can keep their database maintained (little admin programs) but these areas need to be passworded.. and I don't have access to their hoster to see if they support ssl.

In the meantime, I've done md5 encryption but I need a check on each page that requires them to have logged in. Does anybody know how I can set up something to do this? I know how to do it in ASP, it requires to standard pages (maybe you can convert?)

security.asp
Code:
bLoggedIn = (len(session("UserName")) > 0)

if bRequireLogin then
   'Login required
   if Not bLoggedIn then
     'Not logged in, ask for login
     response.redirect "login.asp?comebackto=" & _
     request.servervariables("script_name") & "?" & _
     server.urlencode(request.querystring)
     'Note how we construct the page to come back
   end if
end if

login.asp
Code:
<%
if request("comebackto") <> "" then
   sReferer = request("comebackto")
   sGoBackTo = "?" & request.querystring
end if

   'Login Form submitted
   sUserName = request("txtUserName")
   sPassword = request("txtPassword")


if request("cmdLogin") <> "" then

	 
   'Check for username and password

   if sUserName = "bill" And sPassword = "gates" then
     bLoginSuccessful = True
     session("UserName") = sUserName
     
		 if sReferer = "" then
        response.redirect "default.asp"
     else
        response.redirect sReferer
     end if
   
	 end if
	 



  'After a successful login, let's send the user
  'back to the page requested. The variable sReferer
  'holds the page to go back, if it is empty, we should
  'redirect the user to our default page.
end if



   'Display the Login Form

%>

   <form action="login.asp<%=sGoBackTo%>" method="post">
     <input type="text" name="txtUserName"><br>
     <input type="password" name="txtPassword"><br>
     <input type="submit" name="cmdLogin"><br>
   </form>

and then you insert this at the beginning of whatever page you need them to be logged in to reach

Code:
<%
   bRequireLogin = True
%>

<!--#include file="security.asp"-->

Could anyone help?

Thank you for your time,
Kerry
 
Nvm, I solved it.

I converted the asp to PHP code, and then integrated it into the existing password protection I had and it worked perfectly (after several hours ;)).

If anyone else needs anything like this tell me,
Kerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top