i am trying to make a page to authenticate username and login in php. i know it can be done with session but am not able to figure it out. do i need to write a separate .php file and call it in the other .html file or i need to do something else.can anybody please help me out?
Let me ask you one thing. Are you tring to authenticate a html file or a php file?
If it's a php file then it can be simply done by sessions but if it is a html file then you may try it with iframes. I am not sure if it will work. Else you have to parse the html file through php. This can be done in apache.
I would suggest you to try the iframe method.
i created a login page that is html page and made a connection to access
database through php using adodb.
the login page is displayed by the url lets say www.login.com and when
when i type the correct password it takes me to say www.login.com/page1.html and when incorrect password is given it doesnot
grant the access to the desired page. it works fine till this.
now the problem is when i directly give url www.login.com/page1.html in the
address bar i get the access to the page. so the login page is of no use now.
one can directly access my private without login. so how can solve this problem.
So you want to authenticate a html page. I woul suggest you to use iframe in the html page.
In page1.html use iframe in the top. I hope you know what an iframe is. Let the iframe contain the php code that check for login.
if you are using sessions then you could use like this
i donno about iframe and i am also new to php so really having problem with it!!
i tried your idea using session..but it desnot work....may be i did it the wrong way...can u pls explain it more briefly!!! i would be really be helpful
You have two option either you can use session cookies or just session variables. I would suggest to use session cookies.
//alfter login validation
setcookie ("username", $username); // this will set a cookie without any expiry time. means it will exprie when your session expires or your browser closes.
// this is the code that you have to include in the login validation page.
Now in the after login page you have to include an iframe
<IFRAME SRC="auth.php" HEIGHT="5"></IFRAME>
Let say the file is auth.php
Now in auth.php page you have check for the cookie
this would be like this.