Page 1 of 1

Simple PHP

Posted: Thu Apr 22, 2004 7:22 am
by Think-Digitally
Hi, I am having a problem with the PHP below:

Code: Select all

session_start();

echo "<font size=1 face=Verdana color=#CCCCCC>Welcome ". $_SESSION['first_name'] ." ". $_SESSION['last_name'] .". You are now signed  in.</font><br /><br />";
What I need is for this script to be applied if the user is signed in. If they are not signed in I need it to say that they arent signed in. So I think it needs an 'else' php term. But I am a beginner to PHP.

Is there any chance that anyone can show me what I need to do?

Thanks

Posted: Thu Apr 22, 2004 7:46 am
by magicrobotmonkey
something like this:

Code: Select all

<?php


if(!empty($_SESSION['firstname'])){
  echo "<font size=1 face=Verdana color=#CCCCCC>Welcome ". $_SESSION['first_name'] ." ". $_SESSION['last_name'] .". You are now signed  in.</font><br /><br />"; 
}else
{
  echo "<font size=1 face=Verdana color=#CCCCCC>Please sign in.</font><br /><br />"; 
//or redirect to log in screen or whatever you want to do
}

?>
But I would do something in the log in script like set a $_SESSION[loggedin'] boolean to check rather than the firstname

Not in one script

Posted: Thu Apr 22, 2004 8:00 am
by Lord Sauron
Edited because:
viewtopic.php?t=21171

Posted: Thu Apr 22, 2004 9:16 am
by Think-Digitally
Hi magicrobotmonkey

This is a great script, but for some reason even if I am signed in it says 'Please sign in'.

Anyway that theres anyother way I can get it to work?

Posted: Thu Apr 22, 2004 9:54 am
by magicrobotmonkey
at the top of your page put

Code: Select all

<?php
if(isset($_SESSION['firstname'])){
  echo $_SESSION['firstname'];
}else{
  echo "IT's not even set!";
}
?>

Posted: Thu Apr 22, 2004 10:06 am
by Think-Digitally
Its just says 'IT isnt even set' in the top corner.

Posted: Thu Apr 22, 2004 10:09 am
by magicrobotmonkey
So, what's your log in script look like - that is, what happens before you get to this page?

Posted: Thu Apr 22, 2004 10:11 am
by Think-Digitally
Well when you login on the login page, it uses checkuser.php against the db.
The whole point of the this script I want is to go at the top so it would say Welcome name name, you are signed in, when you have signed in. And if you are logged out it would say please sign in, or register here

Posted: Thu Apr 22, 2004 10:13 am
by dull1554
try this

Code: Select all

<?php

session_start();
$_SESSION['firstname'] = "foobar";

echo "<div>";
print_r($_SESSION);
echo "</div>";

?>
this will print everything in the array, this way you can see if its even getting set.