Need Login/Register page helps

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

terror2012
Forum Newbie
Posts: 3
Joined: Wed Apr 15, 2015 9:32 am

Need Login/Register page helps

Post by terror2012 »

Hello. I tried until today around 50 tutorials. After it I tried myself but nothing works. I just don't know why it's not working.
Every php login/register page I created have some errors. Sometime, the session don't start. Sometime I got a bunch of errors. Can someone give me a simple login page with username and password (which get the encrypted md5 pass from database and check it with current) and if the data are correct, this page should start a session with username and a register page with username, password and email? I just need php scripts.
I'm a php beginner and even with a lot of youtube tutorials, I couldn't do this login. I know the basics of php, but until now I didn't make any serious php script.

Thanks.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need Login/Register page helps

Post by Christopher »

Or, if you show us the code that makes the most sense to you, we could walk you through getting it to work.
(#10850)
fahim
Forum Commoner
Posts: 36
Joined: Sun Jan 05, 2014 7:06 pm
Location: Dhaka, Bangladesh

Re: Need Login/Register page helps

Post by fahim »

Hi everyone,

I'm facing almost same helps. After searching I've found a script which looks good. Here's the link :

http://www.wikihow.com/Create-a-Secure- ... -and-MySQL

I've written all the codes as perfect as possible. But after starting Apache when I'm trying to run index.php. It fails with an error in terminal :
PHP Parse error: syntax error, unexpected 'define' (T_STRING) in /var/www/html/psl-config.php on line 7
At the line 7 of psl-config.php, this line exists :

Code: Select all

define("DATABASE", "secure_login");
I've also created a database with the same name. If you want I can post the database list screen shot here.

Maybe I can't make this work, as I'm so new to PHP, but I believe with your help guys, I can make this work.

Please help. Thanks in advance.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need Login/Register page helps

Post by Christopher »

fahim wrote:I've written all the codes as perfect as possible. But after starting Apache when I'm trying to run index.php. It fails with an error in terminal :
PHP Parse error: syntax error, unexpected 'define' (T_STRING) in /var/www/html/psl-config.php on line 7
At the line 7 of psl-config.php, this line exists :

Code: Select all

define("DATABASE", "secure_login");
According to the link you gave, that line is in the script:

Code: Select all

<?php
/**
 * These are the database login details
 */  
define("HOST", "localhost");     // The host you want to connect to.
define("USER", "sec_user");    // The database username. 
define("PASSWORD", "eKcGZr59zAa2BEWU");    // The database password. 
define("DATABASE", "secure_login");    // The database name.
 
define("CAN_REGISTER", "any");
define("DEFAULT_ROLE", "member");
 
define("SECURE", FALSE);    // FOR DEVELOPMENT ONLY!!!!
?>
The error message means that here is an error before line 7 because it is expecting something other than "define". Check the lines before that you edited to make sure they are correct. Post the whole script if you cannot find the problem.
(#10850)
fahim
Forum Commoner
Posts: 36
Joined: Sun Jan 05, 2014 7:06 pm
Location: Dhaka, Bangladesh

Re: Need Login/Register page helps

Post by fahim »

Really thanks for your reply.

Still unable to find the error in the code :(.

Here's the full code :

Code: Select all

<?php
// These are the database login details

define("HOST", "localhost");						// The host you want to connect to.
define("USER", "sec_user"); 						// The database username.
define("PASSWORD", "eKcGZr59zAa2BEWU") 	// The database password.
define("DATABASE", "secure_login"); 		// The database name.

define("CAN_REGISTER", "any");
define("DEFAULT_ROLE", "member");

define("SECURE", FALSE);								// FOR DEVELOPMENT ONLY!!!!
?>
I believe you'll find it.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need Login/Register page helps

Post by Christopher »

Can you see what is missing in the line before the error?

Code: Select all

define("PASSWORD", "eKcGZr59zAa2BEWU") 	// The database password.
(#10850)
fahim
Forum Commoner
Posts: 36
Joined: Sun Jan 05, 2014 7:06 pm
Location: Dhaka, Bangladesh

Re: Need Login/Register page helps

Post by fahim »

Ufffff !!!! Now I can see it !!! Just a semicolon !!! I'll add it and post the o/p here.

Thank you very much.
fahim
Forum Commoner
Posts: 36
Joined: Sun Jan 05, 2014 7:06 pm
Location: Dhaka, Bangladesh

Re: Need Login/Register page helps

Post by fahim »

Sorry for late post :(

Now when I want to run index.php, the following error appears :
PHP Notice: Use of undefined constant localhost - assumed 'localhost' in /var/www/html/includes/db_connect.php on line 3
PHP Notice: Use of undefined constant sec_user - assumed 'sec_user' in /var/www/html/includes/db_connect.php on line 3
PHP Notice: Use of undefined constant eKcGZr59zAa2BEWU - assumed 'eKcGZr59zAa2BEWU' in /var/www/html/includes/db_connect.php on line 3
PHP Notice: Use of undefined constant secure_login - assumed 'secure_login' in /var/www/html/includes/db_connect.php on line 3
PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'sec_user'@'localhost' (using password: YES) in /var/www/html/includes/db_connect.php on line 3
PHP Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in /var/www/html/includes/functions.php on line 31
First four errors are complaining about "undefined constant" in the db_connect.php file. But I can't find any problems in the code. The code is here :

Code: Select all

<?php
include_once 'psl-config.php';	// As functions.php is not included
$mysqli = new mysqli(localhost, sec_user, eKcGZr59zAa2BEWU, secure_login);
?>
I can't understand the PHP Warning error, as I've jsut copied and pasted the username and password :(

Regarding the final one PHP Parse error, I can't also understand it correctly. The code is here :

Code: Select all

if ($stmt = mysqli->prepare("SELECT id, username, password, salt FROM members WHERE email = ? LIMIT 1"))
I'm drowning in the errors :banghead:
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need Login/Register page helps

Post by Christopher »

Looks like you need some quotes around the string parameters:

Code: Select all

$mysqli = new mysqli(localhost, sec_user, eKcGZr59zAa2BEWU, secure_login);
(#10850)
fahim
Forum Commoner
Posts: 36
Joined: Sun Jan 05, 2014 7:06 pm
Location: Dhaka, Bangladesh

Re: Need Login/Register page helps

Post by fahim »

OH Christopher !!! Really thanks for the help.

After putting the quotes around the string parameters, it is much better. First four messages is now gone, only last two are there. Here it is :
PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'sec_user'@'localhost' (using password: YES) in /var/www/html/includes/db_connect.php on line 3
PHP Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in /var/www/html/includes/functions.php on line 31
Please help.

Best regards.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need Login/Register page helps

Post by Christopher »

Well ... they mean exactly what they say. You don't show the code, but you should be able to find the problems.
PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'sec_user'@'localhost' (using password: YES) in /var/www/html/includes/db_connect.php on line 3
On line 3 it is trying to connect to the database with user 'sec_user'@'localhost' and the supplied password, but the user does not have access to this database or the password is wrong, or the connection failed altogether, etc.
PHP Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in /var/www/html/includes/functions.php on line 31
On line 31, somewhere before the '->' there is a syntax error that is causing the parser to not know what to do when it reaches the '->'. Once you fix the error, the '->' will make sense to the parser.
(#10850)
fahim
Forum Commoner
Posts: 36
Joined: Sun Jan 05, 2014 7:06 pm
Location: Dhaka, Bangladesh

Re: Need Login/Register page helps

Post by fahim »

Thanks for the clarification. user access problem is solved already. Working with the "syntax error" now.
fahim
Forum Commoner
Posts: 36
Joined: Sun Jan 05, 2014 7:06 pm
Location: Dhaka, Bangladesh

Re: Need Login/Register page helps

Post by fahim »

Christopher, I've to thank you again, because according to your advice I've solved both of the errors.

But now I'm facing a new error. This time it's showing :

[text]PHP Notice: Undefined variable: secure in /var/www/html/includes/functions.php on line 20[/text]

The line 20 is a simple variable. You can check here :

Code: Select all

// Gets current cookies params.
	$cookieParams = session_get_cookie_params();
	session_set_cookie_params($cookieParams["lifetime"],
	$cookieParams["path"],
	$cookieParams["domain"],
	$secure,
	$httponly);
Fact is that, I've checked several times to find the mistake on the line 20, but failed to get any error comparing with the main script. I even copy pasted the code,but same errors continues.

I believe you'll show me some lights.

Thanks in advance.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need Login/Register page helps

Post by Celauran »

That shows where $secure is being called. Where is it being defined? You should see $secure = some_value_here farther up. Alternately, var_dump($secure) to check.
Post Reply