Jump to content

another login form^^


kellz

Recommended Posts

yesh..ANOTHER one lol but I'm getting better at it^^ the problem with this 1 is that I cant redirect to the control panel, it tells me that I cant modify the header information because headers were already sent (i know this is because of the sessions) or not? annnywaaay is there another way i could go to the other page? I was going to try javascript but I guess that would have the same affect, right? here is the script:

 

<?php
session_start();
?>
<form name="form1" method="post" action="">
  <label>username
  <input type="text" name="user">
  </label>
  <br>
  <br>
  <label>Password
  <input name="pass" type="password" maxlength="30">
  </label>
  <br>
  <br>
  <input type="submit" name="Submit" value="Login">
</form>
<?php
if (isset($_POST['Submit'])) login();
function login() {
$logged=false;
$tmp = "INSERT INTO `member` ( `loginName`, `password` ) VALUES ('user', MD5( 'password' ));"; //just to remember
if (isset($_POST['user']) && isset($_POST['pass'])) {
        $user = $_POST['user'];
    	$pass = $_POST['pass'];
        $con = mysql_connect("localhost","root","");
    if (!$con) die('Could not connect: ' . mysql_error());
        mysql_select_db("people", $con);
        $sql = "SELECT loginName FROM member WHERE loginName ='$user' AND password =md5('$pass')";
        $result = mysql_query($sql) or die("Couldn't execute query 2."); 
        $num = mysql_num_rows($result);
        if ($num > 0) $logged=true;

	if ($logged == true) {
	    $_SESSION['auth'] = md5(uniqid(microtime()) . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);
        header('location: admin.php'); //error
    }

}
mysql_close();
}

?>

 

btw, OMG I LOVE SQL!! now i know i couldn't live with knowing php and not knowing SQL!!

Link to comment
https://forums.phpfreaks.com/topic/76766-another-login-form/
Share on other sites

<?php
if (isset($_POST['Submit'])) login();
function login() {
$logged=false;
$tmp = "INSERT INTO `member` ( `loginName`, `password` ) VALUES ('user', MD5( 'password' ));"; //just to remember
if (isset($_POST['user']) && isset($_POST['pass'])) {
        $user = $_POST['user'];
    	$pass = $_POST['pass'];
        $con = mysql_connect("localhost","root","");
    if (!$con) die('Could not connect: ' . mysql_error());
        mysql_select_db("people", $con);
        $sql = "SELECT loginName FROM member WHERE loginName ='$user' AND password =md5('$pass')";
        $result = mysql_query($sql) or die("Couldn't execute query 2."); 
        $num = mysql_num_rows($result);
        if ($num > 0) $logged=true;

	if ($logged == true) {
	    $_SESSION['auth'] = md5(uniqid(microtime()) . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);
        header('location: admin.php'); //error
    }

}
mysql_close();
}

?>

 

 

that part of the code HAS to be at the top, I THINK. There is a certain part that has to be at the top, with NOTHING before it not even a space. try that. if that does not work , sorry.

Link to comment
https://forums.phpfreaks.com/topic/76766-another-login-form/#findComment-388658
Share on other sites

you mean :

<?php

session_start();

?>

 

?

I know that has to come first before anything, and it is.. this is (i think) why i cant modify the header (and i dont know what the hell im saying lol) but i think it has something to do with that and i know i cant put anything before session_start();

 

Link to comment
https://forums.phpfreaks.com/topic/76766-another-login-form/#findComment-388663
Share on other sites

Yes, that is correct.  Header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.

 

You could always just do a meta refresh as they can be inserted anywhere....

 

<?php
if ($logged == true) 
{
$_SESSION['auth'] = md5(uniqid(microtime()) . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);
echo "<meta http-equiv=\"refresh\" content=\"0;url=admin.php\">\n";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/76766-another-login-form/#findComment-388668
Share on other sites

you mean :

<?php

session_start();

?>

 

?

I know that has to come first before anything, and it is.. this is (i think) why i cant modify the header (and i dont know what the hell im saying lol) but i think it has something to do with that and i know i cant put anything before session_start();

 

You can have session start before a header, just move all of your login code above the HTML and it should work.

Link to comment
https://forums.phpfreaks.com/topic/76766-another-login-form/#findComment-388673
Share on other sites

thx^^ and now i have another problem on admin.php

 

<?php
session_start();
if (isset($_SESSION['auth'])) {
       if ($_SESSION['auth'] == md5(uniqid(microtime()) . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'])) {
            echo 'hello ';
       }
    } else {
   echo "<meta http-equiv=\"refresh\" content=\"0;url=Untitled-1.php\">\n";
}
?>

 

what bugs me the most about this is that 1 minute it worked fine and then it just stopped working ???

it does nothing.. if i open admin.php without going through the login page then nothing is there it doesnt even redirect to the login page.. if i open it through the login page with the right pass/user then it still does nothing and displays no message.  ::)

Link to comment
https://forums.phpfreaks.com/topic/76766-another-login-form/#findComment-388745
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.