Jump to content


Photo

PHP Login Script (19)


  • Please log in to reply
13 replies to this topic

#1 slaksak

slaksak

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 13 February 2013 - 11:20 AM

Hello my name is Robin and I am new to this forum.

I am trying to learn PHP.

 

I am following Jream's Login script Tutorial below:

 

I have a problem on 11:10. On that point you erase the "Sha1" code in the INdex.php file. But when I do this delete the 2 sentences and safe and clear my cache and restart my browser it stays the same.

The 40 digest code wont dissapear.

Dont I have to End ?> the Login.php file ?

Does somebody know what I did wrong ?

 

I tried Different browsers allready.

And checkt real close on spelling faults..

 

 

Robin


Edited by slaksak, 13 February 2013 - 12:38 PM.


#2 JoeBengalen

JoeBengalen

    Member

  • Members
  • PipPip
  • 20 posts
  • LocationThe Netherlands

Posted 13 February 2013 - 05:40 PM

Ollaah,

 

 

I didnt watch the whole tutorial, but its about a simple echo of a sha1 password.

Echoing something is just showing it to the page for that one load. It has nothing to do with you browser cache or so.

 

If its still showing like you say you must have it echoing somewhere. Cant think of another way.

 

 

Cheers, moi

 

Joe



#3 Simi

Simi

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationRomania

Posted 15 February 2013 - 07:08 AM

Joe has right. You have a echo statement somewhere in your code. Have a look in login.php line 6. There is used a echo for debugging



#4 slaksak

slaksak

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 15 February 2013 - 07:38 AM

<?php
 
require "config.php";
 
$login = $_POST['login'];
$password = $_POST['password'];
 
$db->query("
SELECT COUNT(id) AS total
FROM users
WHERE login = '$login'
AND password = '$password'
");
 
echo $db->get('total');
 
I am still a newbie I echo on the end, but that has Jream in his file too.
It looks like on 10:37 my file is the same ?
 
If i go to: http://localhost/login/index.php   ( its there )
if i go to  file:///C:/Login/index.php             ( its not )
 
I think its right then, just have to look on: file:///C:/Login/index.php and continue ? 
   
He logs in Sandbox/login, i dont have Sandbox should I try to test on: file:///C:/Login/index.php then ?
If I do this it just shows the above file, on his screen @ 12:00 just   ().
 
hm.. please some help:P


#5 JoeBengalen

JoeBengalen

    Member

  • Members
  • PipPip
  • 20 posts
  • LocationThe Netherlands

Posted 15 February 2013 - 10:39 AM

Dont be scared to mess up. Just try to comment out the echo and see what happens.



#6 slaksak

slaksak

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 15 February 2013 - 10:53 AM

If I try to login with:  login:test

                               password:test

 

 

file:///C:/Login/index.php

 

it shows the login.php file.., why does it do this, in the tutorial its empty:   ().



#7 JoeBengalen

JoeBengalen

    Member

  • Members
  • PipPip
  • 20 posts
  • LocationThe Netherlands

Posted 15 February 2013 - 11:10 AM

And you need to use the localhost link. Otherways the php wont be prosessed.



#8 slaksak

slaksak

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 15 February 2013 - 11:16 AM

http://localhost/login/

If I open the above in my browser there is an sha1 40 digest code in the top...

If I login now the browser redirects to  http://localhost/login/index.php.

 

Thats good, but now the sha1 code has to go... but i dont know how..

 

Jream fixes this when he erased the code from Index.php @ 11:08

But if I do this the code stays.

That code is in my users table in my database in my password field.



#9 JoeBengalen

JoeBengalen

    Member

  • Members
  • PipPip
  • 20 posts
  • LocationThe Netherlands

Posted 15 February 2013 - 12:19 PM

You sure you deleted it from the right file?

 

If you cant find it just post all your core here and Ill take alook



#10 slaksak

slaksak

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 15 February 2013 - 12:50 PM

Damm im a fool...

 

Had to work here:

 

C:\xampp\htdocs\Login

 

But I worked in

 

C:\Login

 

I think i copied the login map to the c drive for back-up. 

 

Thanks!! :D

 

dumb me



#11 slaksak

slaksak

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 18 February 2013 - 09:25 AM

Is it difficult to add a Register page to this login ?

Lets say the username with admin authorisation: is able to add users.

 

Maybe it is clever to add a new row to the database with a authorisation level ?

 

- Admin rights

- User rights

 

So on the add user page there is a selection box or something..

 

I learned in this tutorial how to make a page only accesible when logged in.

any advice how to do create this add user page and make it only accesible for certain groups defined in the database? users with Admin authorisation  :) ?



#12 Simi

Simi

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationRomania

Posted 19 February 2013 - 10:30 AM

You have to add a column (not row) "role" in users table like this

 

/* SQL code */
ALTER TABLE `user` ADD COLUMN `role` ENUM('admin','staff','user') DEFAULT 'user'


A new registered user have the role 'user' by default and only admin can change the role in some user interface.

Let say that, after login, you store the user role into a php session and every time you need you can test this variable

... but I think a good start is to watch Create Your Own MVC. This will help you to understand the Model View Controller pattern. With this stuff in mind you can write a better php code even if you are not ready for such a mess :)



#13 slaksak

slaksak

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 19 February 2013 - 03:07 PM

Thanks!



#14 JoeBengalen

JoeBengalen

    Member

  • Members
  • PipPip
  • 20 posts
  • LocationThe Netherlands

Posted 22 February 2013 - 11:03 PM

I have done it on a bit more advanced level I guess.I created 2 other tables in the database. One for the usergroups and one for a hABTM relationship.

If Im logged in with the right rights I can CRUD usergroups and put users in them .

 

I also made another page to define what usergroup is allowed to view what page. But thats way more advanced.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users