0

Hey guys! I want to make a simple login system with PHP, I am pretty noob with php, but have done C++ for like year so understanding the code shouldn't be a problem. Things are done a bit different in the web than in simple program so.. I found this http://www.phpeasystep.com/phptu/6.html and the thing I want to do is when you come to page it asks your password etc and then when you login the page changes to your control panel and you must be logged in to access it. Any ideas guys, and the login is for learning!

2
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by Silvershaft
1

Hey guys! I want to make a simple login system with PHP, I am pretty noob with php, but have done C++ for like year so understanding the code shouldn't be a problem. Things are done a bit different in the web than in simple program so.. I found this http://www.phpeasystep.com/phptu/6.html and the thing I want to do is when you come to page it asks your password etc and then when you login the page changes to your control panel and you must be logged in to access it. Any ideas guys, and the login is for learning!

That tutorial should do it for you. When you get to login_success.php, add an else here:

if(!session_is_registered(myusername)){
header("location:main_login.php");
}

Then use the $_SESSION to determine the user who is logged in and display their control panel.

0

So I should do like if I want to test is user logged in I put statement and if user is logged in I include php file with the control panel or if he isn't I include php file with the login form, that way?

0
<?
session_start();
if(!session_is_registered(myusername))
{
	header("location:Main.php");
	echo "Something";
}
else
{
	echo "lol";
}
?>

<html>
<body>
Login Successful
</body>
</html>

This part doesn't somehow work, it won't echo those things :S

0

The checklogin.php page in that tutorial already validates the login. If you find that the $_SESSION variable is set (it's set in the checklogin.php page), you already know that they are logged in successfully and you can present the control panel or whatever other content you need based on the username.

0

So I add the control panel code to login_success file? And how I can put my pages URL look like www.page.com?page=Main and Page=ControlPanel and so on? And what if user goes straight to login_success.php?

Bah I can't get it, why can't I even echo anything in that file they just won't show up!

Edited by Silvershaft: n/a

0

So I add the control panel code to login_success file?

Yes. Or create a new page that you can link to if you like. After setting the session variables you can put the

session_start()

function on any page and access any session variables you have set.

And how I can put my pages URL look like www.page.com?page=Main and Page=ControlPanel and so on?

That's kind of a whole other topic. You may want to start a new thread for that, but basically your index page will be getting the $_PUT variables and deciding what content to show based on that.

And what if user goes straight to login_success.php?

That's what the first part of login_success.php is for:

if(!session_is_registered(myusername)){
header("location:main_login.php");
}

It says that if myusername is not registered as a session variable, re-direct back to the login page (cause you didn't log in yet, you cheater!).

Here's a good overview of the basics of sessions: http://www.tizag.com/phpT/phpsessions.php

0

I just don't get it why it doesn't redirect if I enter it straight on the browser I mean the login_success.php

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.