Search
Left Quote    Nearly all men can stand adversity, but if you want to test a man's character, give him power.
- Abraham Lincoln    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Login/Session help needed please.
  This user is offline  xecu
  Subject: "Login/Session help needed please." Posted: @ 9:47 pm on Mar 01 2008   
Member #: 599
Rank: User - (6)
Since: 02/27/08
Posts: 6
From: New York City

I am trying to make an all inclusive access.php to include on all my pages so that it checks whether or not you are logged in or not, and to show login screen if not. I am still very new with php, this is what I have so far, and I can't seem to make it work.

Code:

<?php
include_once 'common.php'; // helps determin error messages
include_once 'db.php'; // logs in to database

session_start() ;

$reguname = isset($_POST['u name']) ? $_POST['uname'] : $_SESSION['unam e'];
$regpword = isset($_POST['p word']) ? $_POST['pword'] : $_SESSION['pwor d'];

if(!isset($regu name)) {
?>
blah blah
<form method="po st" action="&l t;?=$_SERVER['P HP_SELF']?>& quot;>
<b>Userna me:</b> <input size="10&q uot; type="text " name="unam e">
<b>Passwo rd:</b> <input size="10&q uot; type="pass word" name="pwor d">
<input type="subm it" name="Subm it" value="Log in">< ;/form>
blah blah
</html> <?php
exit;
}

dbConnect(" ;dbusr");< br />
if ($_POST['uname' ]=='' or $_POST['pword'] =='') {
error('error');
}

$_SESSION['unam e'] = $reguname;
$_SESSION['pwor d'] = $regpword;

$sql = "SELECT * FROM user WHERE
uname = '$reguname' AND pword = PASSWORD('$regp word')";
$result = mysql_query($sq l);
if (!$result) {
error('error');
}

$count = mysql_num_rows( $result);

if($count==0) {
unset($_SESSION ['uname']);
unset($_SESSION ['pword']);
error("Wro ng Username or Password") ;
}

?>




Please Help.


You see heaven, before you see hell. - Xecu
    Viewed: 5,177 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Login/Session help needed pleas..." Posted: @ 12:49 am on Mar 05 2008    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA




-bs0d | AllSyntax.com

    Viewed: 5,134 Times | Reply to This | To top
  This user is offline  xecu
  Subject: "re: Login/Session help needed pleas..." Posted: @ 10:12 am on Mar 06 2008    
Member #: 599
Rank: User - (6)
Since: 02/27/08
Posts: 6
From: New York City

Thanks, looks very promising.




You see heaven, before you see hell. - Xecu

    Viewed: 5,113 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank