How to refresh the page

Started by Thunderace, June 10, 2005, 03:08:27 PM

Previous topic - Next topic

Thunderace

I'm following the SMF example of running a script  from initial index.php.

I'm calling a function which is giving me a login box under the header when user isn't logged.

If he IS logged I'm calling a different function to say welcome $user.

My problem is that the login echo ' is remaining and the "logged in" echo ' is just adding underneath.

Any help appreciated.

Cheers

Rob

Thunderace

Perhaps it is that this isn't working ..

if (empty($user)) {
include($dir . '/header.php');
    userin();
}


When I say not working, it's fine, it recognises that the user is not logged in and calls the function, but second time around when user IS NOT (!empty()) it still seems to run.

[Unknown]

Can you post a little more detail?

-[Unknown]

Thunderace

require_once($actionsdir . '/login.php');
//start the session
sess();

//Check if user is logged in and show appropriate info under header
if (empty($name)) {
include($actionsdir . '/header.php');
    login();
}
if (!empty($name)) {
include($actionsdir . '/header.php');
loggedin();
}
?>

[Unknown]

Does using an else instead help?

You seem to be using register_globals a lot... generally, I consider that to be rather brittle, so it's hard to fix and find problems with its use.

-[Unknown]

Thunderace

Ok don't forget I'm a totally green coder  :D

I have solved the problem of refresh by using ..

if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'login')

However I now can't pass the variable $_POST['user'] to the next 'action'

[Unknown]

Why can't you pass that variable?  I'm not sure I understand.

-[Unknown]

Thunderace

Seems to me that if ?action calls a script it retains the "settings" from index.php.

If that script then calls another ?action then the settings are lost in the next script, dunno why.

[Unknown]

Variables aren't persistant, they have to be reloaded every request.

-[Unknown]

twoeyes

Well you can pass the variable by setting a session (hxxp:us3.php.net/manual/en/ref.session.php [nonactive]) basicly all you do is put

session_start();

at the top of all your pages, then you use the following code:

$_SESSION['user'] = $username;

That will assign the correct value to the session, like any other variable. Next in order to access the value you use:

$_SESSION['user']

This will hold it's value as long as the user has his browser window open, when it closes the value will be deleted, so it's not like a cookie, but a bit more secure for noobies *cough* green coders :P

Thunderace

What i was looking for twoeyes was index.php?action=thisaction&this=blurb&that=moreblurb  ;)

But thanks for the n00b lessons in basic sessions  :P

Advertisement: