www.webdeveloper.com
Results 1 to 3 of 3

Thread: Login Script Troubles

  1. #1
    Join Date
    Jan 2009
    Location
    127.0.0.1
    Posts
    126

    Login Script Troubles

    I have been working on this for a day and a half. I think something is messed up with the headers but i can't figure out what.

    The way the script works is the user inputs a username and password. i take that and compare to the database. if they appear on the same row i get that row. if the row is greater than 0 they should be logged in and transfer to another page.

    if they fail the log in they are forwarded to the same page. on that page there is a script that should reject anyone who hasn't logged in but it's not working correctly. basically i can't log in at all.

    im going to paste the login script then the page that is being linked to and the script that should limit who gets in.

    Code:
    <?php
    error_reporting(E_ALL);
    
    //function pre($array) { echo sprintf("<pre>%s</pre>", print_r($array, true)); }  pre($_POST);
    
    
    	//declaration of variables
    		//creating connection to serve
    	$con = mysql_connect("localhost","db","pass") or die('Could not connect to server' . mysql_error());
    	$table = "user_pass";
    	$db = "whackand_wikieng";
    
    		//making user input safe
    	mysql_select_db($db, $con);
    	$username = mysql_real_escape_string($_POST['username']);
    	$password = mysql_real_escape_string($_POST['password']);
    	//$username = $_POST["username"];
    	//$password = $_POST["password"];
    
    	$result = mysql_query("SELECT Number FROM $table WHERE Username = '$username' AND Password = '$password'");
    	$row = mysql_num_rows($result);
    	
    	//echo $row;
    	//echo $id;
    
    	if($row > 0)
    	{
    	session_start();
    	$_SESSION['authenticate'] = 1;
    	header("Location: upload_form-1.php");
    	}
    	/*else
    	{
    	session_start();
    	$_SESSION['authenticate'] = '';
    	header("Location: upload_form-1.php");
    	}*/
    
    	
    	//closing server connection
    	mysql_close($con);
    
    
    ?>

  2. #2
    Join Date
    Jan 2009
    Location
    127.0.0.1
    Posts
    126
    here is the script from the top of the page being linked to. after that it is just a bunch of html and css (to much to fit here).

    Code:
    <?php
    
    if($_SESSION['authenticate'] != 1)
    	{
    	header("Location: display.php");
    	}
    ?>

  3. #3
    Join Date
    May 2010
    Location
    Manila, Philippines
    Posts
    189
    I saw that you tried to look for the value of $row to make sure what condition is being processed don't you.. is the if($row > 0) condition getting through? I haven't tried the code yet though coz I'm still in my office.

    Also, could you move your session_start() at the very top of the codes. It should be always at the top of the codes remember that... =)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles