PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Below is my code I am using on a page it worked fine for showing my flash chat if name was set in a session and showing a message instead if name wasnt set yet, Now though I need to show a different chat if there age is over a certain again in the middle of the code you will see where I need this added I am lost any help greatly appreciated
$age = 12; // Use an integer instead of a string
if ((isset($_SESSION['mycribname']) && ($age >= 18)) {
// output html for people 18 and over
}
else if ((isset($_SESSION['mycribname']) && ($age < 18)) {
// output html for people under 18
}
else {
// Output message to make them go to url
}
Personally, I don't like using multiple <?php ?> tags, it's too easy for me to miss things like brackets. You may want to use the heredoc syntax, IMHO, less trouble, and easier to maintain. Your code using heredoc syntax would look like this:
Of course, you don't have to, do it however you're comfortable with.
edit: didn't notice that other embed php tags, look at the next post for a better way.
Last edited by blackbeard on Mon Aug 28, 2006 5:34 pm, edited 2 times in total.
thanks I do like this method better but I still get error with that code
Parse error: parse error, unexpected '{' in /home/mycrib/public_html/chat/index2.php on line 5
blackbeard wrote:Personally, I don't like using multiple <?php ?> tags, it's too easy for me to miss things like brackets. You may want to use the heredoc syntax, IMHO, less trouble, and easier to maintain. Your code using heredoc syntax would look like this:
This is a great example of why you should separeate your programming from your presentation. It makes it much easier to see what is going on and promotes reuse.
<?PHP
$age =12;
session_start(); // need to be called once
if ((isset($_SESSION['mycribname']) && ($age >= 88)) {
$params = 'init_user=' . $_SESSION['mycribname'] . '&init_password=&init_listroom=1001,1002,1003,1004';
include 'templates/chat.php';
} else if ((isset($_SESSION['mycribname']) && ($age < 18 )) {
$params = 'init_user=&init_listroom=1001,1002,1003,1004';
include 'templates/chat.php';
} else {
echo 'You must come from Mycrib.net to enter the chat <a href="http://mycrib.net/?pageid=mycrib.member.profile.home">Click here</a>';
}
?>
interesting way to do it, but this still creates same error as other ways tried
Parse error: parse error, unexpected '{' in /home/mycrib/public_html/chat/index2.php on line 4
arborint wrote:This is a great example of why you should separeate your programming from your presentation. It makes it much easier to see what is going on and promotes reuse.
<?PHP
$age =12;
session_start(); // need to be called once
if ((isset($_SESSION['mycribname']) && ($age >= 88)) {
$params = 'init_user=' . $_SESSION['mycribname'] . '&init_password=&init_listroom=1001,1002,1003,1004';
include 'templates/chat.php';
} else if ((isset($_SESSION['mycribname']) && ($age < 18 )) {
$params = 'init_user=&init_listroom=1001,1002,1003,1004';
include 'templates/chat.php';
} else {
echo 'You must come from Mycrib.net to enter the chat <a href="http://mycrib.net/?pageid=mycrib.member.profile.home">Click here</a>';
}
?>
<?php
session_start(); // need to be called once
$age = 12;
$msg = '';
if ( isset($_SESSION['mycribname']) )
{
if ( $age >= 88 )
{
$params = 'init_user=' . $_SESSION['mycribname'] . '&init_password=&init_listroom=1001,1002,1003,1004';
}
else if ( $age < 18 )
{
$params = 'init_user=&init_listroom=1001,1002,1003,1004';
}
include 'templates/chat.php';
}
else
{
$msg = 'You must come from Mycrib.net to enter the chat <a href="http://mycrib.net/?pageid=mycrib.member.profile.home">Click here</a>';
}
echo $msg; // Or use this in your HTML somewhere
?>