PDA

View Full Version : help with php page


pspmixer
03-11-2014, 04:32 PM
im trying to create a login page for website so people who are registered can view my videos
when i testing the page with wampserver it just loops on the login page even though I enter correct details
any able to help me on this please

edbr
03-12-2014, 01:06 AM
then the address is not validating with the db or the redirect is wrong.
without the relevant code no one can help.
Post the part that redirects first.

pspmixer
03-12-2014, 11:16 AM
here is all my code for that page
<?php require_once('Connections/User_Information.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
$loginUsername=$_POST["username"];
$password=$_POST["password"];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "sports login.php";
$MM_redirectLoginFailed = "denied.html";
$MM_redirecttoReferrer = false;
mysql_select_db($database_User_Information, $User_Information);
$LoginRS__query=sprintf("SELECT username, password FROM users WHERE username=%s AND password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $User_Information) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Sports Login</title>
<!-- TemplateEndEditable -->
<style type="text/css">
body,td,th {
color: #000;
font-family: Arial, Helvetica, sans-serif;
}
body {
background-color: #0F6;
background-repeat: repeat;
font-family: Arial, Helvetica, sans-serif;
}
.title {
text-align: center;
}
.copyright { font-size: 12px;
}
</style>
</head>
</p>
<img src="images/TECHKAOSbanner.jpg" width="900" height="200" />
<hr/>
<p><a href="file:///C|/Users/HP/Desktop/website/index.html">HOME</a></p (file:///C:/Users/HP/Desktop/website/index.html%22%3EHOME%3C/a%3E%3C/p)>
<p></p>
<html>
<h1>To Access Sports Please Login In</h1>
<form ACTION="<?php echo $_SERVER["PHP_SELF"];
}
?>" METHOD="POST" id"sports_login" name="sports_login">
Username:<br />
<input name"username" type="text" required="required" id="username" form="sports_login" title="username" autocomplete="on" /><br />
Password<br />
<input name"password" type="password" required="required" id="password" title="password" />
<br />
<input type="submit" value="Login" /><br />
</form>
<p><a href="register.php">Register</a>
</p>
</html>
</p>
<p class="copyright">Copyright Techkaos 2014&copy;</p>

edbr
03-13-2014, 01:20 AM
$MM_redirectLoginSuccess = "sports login.php"; thats why it loops to the login page I would think.

pspmixer
03-17-2014, 06:00 PM
so how do I fix this then

edbr
03-18-2014, 01:28 AM
direct the successful login to a page that you want

edbr
03-18-2014, 03:21 AM
look, here is a less code flooded login system, it one i put together but havent used any encoding or salting on this version
make a file called login.php. edit the user password data base and table from where the datd will be for log in

<?php session_start();
$hostname = "localhost";
$username= "test";
$password = "test";
$database ='test';
try {
$pdo = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
}
catch(PDOException $e)
{
echo $e->getMessage();
}

$sql= "SELECT * FROM usermanager "; //edit table
$stmt = $pdo->query($sql);
$row =$stmt->fetchObject();
?>
<div align="center" >
<span style="background-color:#999">

<?php
$ADMIN_USER = $row->username;
$ADMIN_PASSWORD = $row->password;
if(!$_SESSION['authenticated'])
if($_POST['loginbutton']) {
$inputuser = $_POST['input_user'];
$inputpassword =sha1($_POST['input_password']);
echo $inputpassword.'<br>';
echo $ADMIN_PASSWORD;
if(!strcmp($inputuser ,$ADMIN_USER) && !strcmp($inputpassword,$ADMIN_PASSWORD)) {
$_SESSION['authenticated'] = 1;
header("Location:index.php");
}
else
displayform(1);
}
else
displayform(0);
function displayform($error) {
echo "<html><head><title>Please login</title></head><body><style>
table{ margin-top:100px;}
td{ font-family: verdana; font-size: 8pt; background-color:#999; input background-color:#fff; }</style>";
if($error) echo "<p><b>Wrong credentials.</b></p>";
echo "<form action=\"\" method=\"post\"><table width='300' border=0 ><tr><td width='100'>username:</td>";
echo "<td><input type='text' name='input_user'></td></tr><tr><td>password:</td><td><input type='password' name='input_password'></td></tr>";
echo "<tr><td colspan='2'><input type='Submit' value='Login&raquo;' name='loginbutton'></td></tr></table></form></body></html>";
exit;
}
?>
</div>


then at the top of any protected page requiring login add this

<?php @include "login.php";
if(!strcmp($inputuser ,$ADMIN_USER) && !strcmp($inputpassword,$ADMIN_PASSWORD)) {
$_SESSION['authenticated'] = 1;
header("Location:".$_SERVER[PHP_SELF]);
}
?>
if not logged in you will be redirected tpo login and the form

pspmixer
03-18-2014, 09:17 PM
sorry I didn't understand that , could I do remote link with you using teamviewer, if so what's best time for you as im in uk

edbr
03-19-2014, 12:13 AM
No but I will put up an example for download later which hopefully will help

pspmixer
03-19-2014, 10:00 PM
ok thanks mate

jmichae3
04-02-2014, 10:39 PM
XHTML does not work in IE (well, at least older versions).
it should be avoided if possible - stick with HTML5.

pastebin.com is also a method to post code, with color syntax highlighting.

that session should probably have a .close()

pspmixer
04-07-2014, 09:34 PM
any more help on this thanks