PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Sep 20, 2019 10:41 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Simple PHP
PostPosted: Thu Apr 22, 2004 7:22 am 
Offline
Forum Commoner

Joined: Wed Feb 04, 2004 3:25 pm
Posts: 25
Hi, I am having a problem with the PHP below:

Syntax: [ Download ] [ Hide ]
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 7:46 am 
Offline
Forum Regular

Joined: Sun Mar 21, 2004 2:09 pm
Posts: 888
Location: Cambridge, MA
something like this:

Syntax: [ Download ] [ Hide ]
<?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


Top
 Profile  
 
 Post subject: Not in one script
PostPosted: Thu Apr 22, 2004 8:00 am 
Offline
Forum Commoner
User avatar

Joined: Tue Apr 20, 2004 5:53 am
Posts: 85
Location: Tilburg, NL


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 9:16 am 
Offline
Forum Commoner

Joined: Wed Feb 04, 2004 3:25 pm
Posts: 25


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 9:54 am 
Offline
Forum Regular

Joined: Sun Mar 21, 2004 2:09 pm
Posts: 888
Location: Cambridge, MA
at the top of your page put

Syntax: [ Download ] [ Hide ]
<?php

if(isset($_SESSION['firstname'])){

  echo $_SESSION['firstname'];

}else{

  echo "IT's not even set!";

}

?>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 10:06 am 
Offline
Forum Commoner

Joined: Wed Feb 04, 2004 3:25 pm
Posts: 25


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 10:09 am 
Offline
Forum Regular

Joined: Sun Mar 21, 2004 2:09 pm
Posts: 888
Location: Cambridge, MA


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 10:11 am 
Offline
Forum Commoner

Joined: Wed Feb 04, 2004 3:25 pm
Posts: 25


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 10:13 am 
Offline
Forum Regular
User avatar

Joined: Sat Nov 22, 2003 12:26 pm
Posts: 680
Location: 42:21:35.359N, 76:02:20.688W
try this

Syntax: [ Download ] [ Hide ]
<?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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group