Hooo
-
Posts
28 -
Joined
-
Last visited
Never
Posts posted by Hooo
-
-
deecee2000 you was spot on, thankyou.
I firstly tried pengu's suggestion, however that simply made me redirect back to index.php even when I logged in correctly.
Solved
-
I have been searching for hours for a problem which resembles mine with no luck... Basically I am starting my own little project and want a Login which works (Obviously...)
Anyway, what I have so far is my index.php page has the login form on, you login and the "Login" button checks the checklogin.php page which does the SQL stuff and sets the session (I think), then of course if the User/Pass rows match the user is directed to login_success.php. Now this is all well and good, and the wrong User/Pass inputted it will tell you this with the else statement on checklogin.php.
However, here is the problem, if I type the direct URL to login_success.php, it will still tell me Login Successful, even after ending the session. Now of course I want it so you can only access login_success.php if you have logged in, otherwise there is no point in needing to login right?, anyway, you should be redirected to index.php to relogin when trying to access this page, and I don't see why this isn't happening.
Code is below:
Checklogin.php
<?php
include 'config.php';
include 'opendb.php';
$tbl_name= 'Users';
$myusername=$_POST['usname'];
$mypassword=$_POST['userpass'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM " .$tbl_name ." WHERE usname='" . $myusername. "' and userpass='".$mypassword."'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count == 1) {
$_SESSION['usname'] = $myusername;
echo '<meta http-equiv="refresh" content="2;url=http://www.WEBSITE.com/login_success.php">';
}
else {
echo "Wrong Username or Password";
}
include 'closedb.php';
?>
login_success.php
<?
include 'config.php';
include 'opendb.php';
session_start();
if(!isset($_SESSION['usname']))
{ header("location:index.php");
}
?>
<html>
<body>
Login Successful<br /><br />
<a href="http://www.WEBSITE.com/logout.php">Logout</a>
</body>
</html>
Any help on this would be so appreciated
[SOLVED] Mysql + Echo Variable
in PHP Coding Help
Posted
Stupid problem indeed, i'm basically trying to echo a name I have grabbed using an array, and put into a variable (Or something like that?)
Sorry if this is so stupid, at the moment its coming up on main.php:
Login Successful
Your name is:
Logout