PDA

View Full Version : trying to get login script to work properly


Josh
11-02-2010, 02:18 AM
Hi,

i've been trying to all night to figure out what's wrong, no luck.

I am at the stage where I have a login page, with username and password, my database works fine. all passwords match up etc. I followed the tutorial from here: http://www.youtube.com/watch?v=4oSCuEtxRK8&feature=channel not at the registration part, just the login bit.

So that tutorial tells you how to create a login form using blank php files, however i've got templates that I want my login script to be placed on and used on.

i've put the sign in bit on my website, that directs me to a login with username and password using a html form thats integrated into my pages.

Now this is the confusing bit for me.

When I click log in, I want it to take me to a members page, which at the moment is a page from my template, with no content written yet. named member.php

however the following code:

<?php
session_start();
if ($_SESSION['username'])
echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a>";
else
die("You are not logged in");
?>

it does open up my template member.php, but it adds the Welcome message, and the logout button, above my template, thus making the website drop down.

All I want it to do is to open up the member.php page, as if I were a logged in user, but that code is preventing me from doing that.

have a look for yourself on my website, try signing in, username = josh

password = woolwich www.onlinestage.co.uk (http://www.onlinestage.co.uk)

I don't need the logout button in the php because i've got one in my header, and I don't want the welcome message in the php, i want it in the html code of the editable region,but as soon as I take it out of the php, it doesn't navigate to the member.php, it's just blank.


Sorry if this is very confusing,

Any help is appreciated,

Thanks.

edbr
11-02-2010, 02:32 AM
you have added this before the html tag. This part shoud be in the page in php tags
if ($_SESSION['username'])
echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a>";
else
die("You are not logged in");

Josh
11-02-2010, 01:41 PM
ah brilliant, it works ok now, i wasn't aware you could put php tags into html, thanks very much.

now to see what my next hurdle is!!