Page 1 of 1

Login Script

Posted: Wed Apr 04, 2007 9:26 am
by enemeth
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi there all !  

I got a log in script that just seems to be giving me a hard time ! 

the checkuser.php file is as follows:

Code: Select all

<? 
/* Check User Script */ 
session_start();  // Start Session
include 'db.php'; 
// Conver to simple variables 
$username = $_POST['username']; 
$password = $_POST['password'];
if((!$username) || (!$password)){ 
    echo "Please enter ALL of the information! <br />"; 
    include 'login.php'; 
    exit();
}
// Convert password to md5 hash 
$password = md5($password);
// check if the user info validates the db 
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1'"); 
$login_check = mysql_num_rows($sql);
if($login_check > 0){ 
    while($row = mysql_fetch_array($sql)){ 
    foreach( $row AS $key => $val ){ 
        $$key = stripslashes( $val ); 
    } 
        // Register some session variables! 
        session_register('first_name'); 
        $_SESSION['first_name'] = $first_name; 
        session_register('last_name'); 
        $_SESSION['last_name'] = $last_name; 
        session_register('email_address'); 
        $_SESSION['email_address'] = $email_address; 
        session_register('special_user'); 
        $_SESSION['user_level'] = $user_level;
        mysql_query("UPDATE users SET last_login=now() WHERE userid='$userid'");
        header("Location: login_success.php"); 
    } 
} else { 
    echo "You could not be logged in! Either the username and password do not match or you have not validated your membership!<br /> 
    Please try again!<br />"; 
    include 'login.php'; 
} 
?>

On the form i enter my user name and password that was supplied to me via my activate.php email that was sent , but when i enter the username and password and try to log in , it gives me the first part of the checkuser.php error that i have to enter ALL the information, it never gets past that part of the code. Now unless im going looney ! which hey after 2 weeks of setting this thing up! i may very well be going !

i am doing everything right , does anyone see why in the above code? maybe im just not seeing it !

Help ! anyone ;)

Thanks for your help :)

Elaine


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Apr 04, 2007 9:50 am
by kpraman
try this,

Code: Select all

echo $username = $_POST['username']; 
echo $password = $_POST['password'];
are you getting any values?

Posted: Wed Apr 04, 2007 9:54 am
by enemeth
Still having the same error after changing that

values? im new to this , where would i look to see if i am getting values?

sorry for my ignorance, i made it this far ! lol

Elaine

Posted: Wed Apr 04, 2007 10:00 am
by feyd
Run the following in a new file and tell us the results please.

Code: Select all

<?php

$neg = array('off', 0, false, '', null);
$flags = array(
	'Register Globals' => 'register_globals',
	'Short Tags' => 'short_open_tag',
	'Display Errors' => 'display_errors',
	'Magic Quotes GPC' => 'magic_quotes_gpc',
	'Magic Quotes Runtime' => 'magic_quotes_runtime',
	'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
	$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$flags['Config file'] = get_cfg_var('cfg_file_path');
if (empty($flags['Config file']))
{
	$flags['Config file'] = '-';
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";

$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
	$le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . $eol;
}

$ec = array(
	'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
	'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
	'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
	'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
	if (($t & $v) == $v)
	{
		$e[] = $n;
		$t ^= $v;
	}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
	$e2 = array();
	foreach ($ec as $n => $v)
	{
		if (!in_array($n, $e) and $n != 'E_ALL')
		{
			$e2[] = $n;
		}
	}
	$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
	$er = $er . ' (' . implode(' | ', $e) . ')';
}

if (!$cli)
{
	echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}

echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
	echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;

if (!$cli)
{
	echo '</pre></body></html>', $eol;
}

?>

Posted: Wed Apr 04, 2007 10:00 am
by kpraman
It seems, the values are not getting posted.

give full code(HTML form)

Posted: Wed Apr 04, 2007 10:16 am
by enemeth
PHP Version: 4.4.0
PHP OS: Linux
Error Reporting: 2039 ((E_ALL | E_STRICT) ^ E_STRICT ^ E_NOTICE))
Register Globals: On
Short Tags: On
Display Errors: On
Magic Quotes GPC: On
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Config file: /usr/local/Zend/etc/php.ini
Loaded Extensions:
xslt xml tokenizer standard
session posix pcre overload
mysql mhash mcrypt mbstring
imap gettext gd ftp
exif domxml curl ctype
calendar bcmath zlib openssl
ionCube Loader Zend Optimizer


this is what i get when i run the code you gave me

Posted: Wed Apr 04, 2007 10:18 am
by feyd
Add the following to the top of your script (immediately after the open tag) and test it again.

Code: Select all

error_reporting(E_ALL);

Posted: Wed Apr 04, 2007 10:24 am
by enemeth
Notice: Undefined index: username in /home/www/thetruthdiscovered.com/checkuser.php on line 6

Notice: Undefined index: password in /home/www/thetruthdiscovered.com/checkuser.php on line 7
Please enter ALL of the information!

this is what i get when doing that

and the opening tag is <? right?

Elaine

Posted: Wed Apr 04, 2007 10:28 am
by feyd
You used the form to check that, correct?

<? is an open tag, although you really shouldn't be using it. It should be "<?php"

Also, of note is session_register() should not be used anymore. You also need to read up on SQL injection and header() based redirection.

Posted: Wed Apr 04, 2007 10:34 am
by enemeth
i placed
error_reporting(E_ALL);

on the top of my script checkuser.php and tried to log in again and recieved that error i pasted

was that what you wanted me to do?

the sessions part , well it was included in the code i got off of a site that gave an instruction tutorial on how to create a membership login , im not very familur with all this i am just doing it step by step and i got all the registration part done it works fine , it sends the confirmation email, it activates the account , but never can log in , stuck there,

i really am new at it! any help is appreciated, and i appreciate all you have tried :)

but im going to pull out my hair soon !

;) Elaine

Posted: Wed Apr 04, 2007 10:42 am
by feyd
Just so you know, the tutorial you found was written for a pretty old version of PHP (or written very poorly.)

Since you say you used the form to test the script, the form isn't submitting the proper information to your script. Post it.

Posted: Wed Apr 04, 2007 10:47 am
by enemeth

Code: Select all

<center>
<form action="checkuser.php" method="post">
<table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td><font face="Calligraphic" font color="white">Username:</td><td><input type="text" name="user" maxlength="30"></td></tr>
<tr><td><font face="Calligraphic" font color="white">Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr>
<tr><td colspan="2" align="center"><input type="submit" name="sublogin" value="Login"></font></td></tr>

</table>
</form>
</center>
this is the form i use to log in

Elaine

Posted: Wed Apr 04, 2007 10:56 am
by feyd
Note that the names of the fields are "user" and "pass" not "username" and "password", respectively.

Posted: Wed Apr 04, 2007 10:58 am
by enemeth
Oh MY MY MY

you did it

That is wonderful it works ! i cant believe i didnt see that , actually i can !

but amazing i would of never ever looked there !!

Thank you sooooo very much feyd!

you dont no how much i appreciate it !

thank you again,

Elaine