Jump to content

Securing Pages


havox

Recommended Posts

Hello everyone, this is my first post. This isn't just a simple post and leave, I'm looking to expand into this community and learn as much as I can. Well on to the problem at hand!

 

I decided to start with something simple as a login page and now want to expand it to make it fully functional.

 

<html>
<head>
<title>Deadnode.com</title>
<LINK href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div style=width:150px;height:80px;position:absolute;left:40%;top:35%;
margin-left:-135px;margin-top:-50px;">

<div class="sidebox">
<div class="boxhead"><h2>Login Required</h2></div>
<div class="boxbody">
<form method="post" action="check.php">
<center><table>

<tr><td><font face="verdana,arial" size=-1>User:</td><td><input type="text" name="user"></td></tr>
<tr><td><font face="verdana,arial" size=-1>Pass:</td><td><input type="text" name="pwd"></td></tr>
<tr><td><font face="verdana,arial" size=-1> </td><td><font face="verdana,arial" size=-1><input type="submit" value="Login"></td></tr>
</table></center>
</form>
</div>

</div>
</body>
</html>

 

<?php
function check() {
$admin="test";
$pass="test";
if ( $_POST["user"] == $admin & $_POST["pwd"] == $pass) {
  header('Location: output.php'); }
else {
  header('Location: index.html'); }
}
?>

 

<?php
require('function.php');
check();
?>

 

This is just the code in it originally form; completely functional. I tried to use start_session() in my check() function. I know I should be using cookies, but I haven't gotten that far yet. Is it possible to use my check function as a way to block pages? I tried inserting the same code that is in check.php onto a html page, but I've had no luck with it redirecting back to my index.html page.

Link to comment
https://forums.phpfreaks.com/topic/218597-securing-pages/
Share on other sites

That's making me think you should probably be getting a 'headers already sent' error. As the very first thing in the script that you're having problems with, put this and see if there are any errors reported.

error_reporting(-1);
ini_set('display_errors', 1);

 

Unrelated to the current problem, but any time you use a header() redirect, you should call exit() immediately after it to prevent any further execution of code in the script.

Link to comment
https://forums.phpfreaks.com/topic/218597-securing-pages/#findComment-1133913
Share on other sites

Here is one comes up now

 

Notice: Undefined index: user in /srv/www/deadnode.com/public_html/function.php on line 7

 

Notice: Undefined index: pwd in /srv/www/deadnode.com/public_html/function.php on line 7

 

Warning: Cannot modify header information - headers already sent by (output started at /srv/www/deadnode.com/public_html/function.php:7) in /srv/www/deadnode.com/public_html/function.php on line 10

 

Link to comment
https://forums.phpfreaks.com/topic/218597-securing-pages/#findComment-1133976
Share on other sites

Updated function.php

 

<?php
function check() {

$admin="test";
$pass="test";

        if (isset( $_POST["user"] == $admin & $_POST["pwd"] == $pass)) {
          header('Location: output.php'); }
        else {
          header('Location: index.html'); }
}
?>

 

I tried using isset(). Good thing is It doesn't print the contents of the page out, but I do get this error.

 

Parse error: syntax error, unexpected T_IS_EQUAL, expecting ',' or ')' in /srv/www/deadnode.com/public_html/function.php on line 7

Link to comment
https://forums.phpfreaks.com/topic/218597-securing-pages/#findComment-1134104
Share on other sites

function check() {

$admin="test";
$pass="test";

        if (isset($_POST["user"]) && $_POST["user"] == $admin && isset($_POST["pwd"]) && $_POST["pwd"] == $pass) {
          header('Location: output.php');
          exit;
       } else {
          header('Location: index.html');
          exit;
       }
}

Link to comment
https://forums.phpfreaks.com/topic/218597-securing-pages/#findComment-1134133
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.