Forum Moderators: coopster
$ChatPath = "../mychat/chat/";
$ChatLaunch = "<A HREF=\"../mychat\chat\" TARGET=\"_self\">chatting</A>";
$ShowPrivate = "0";
$DisplayUsers = "1";
define("NB_USERS_IN","users are ".$ChatLaunch." at this time.");
define("USERS_LOGIN","User ".$ChatLaunch." at this time:");
define("NO_USER","Nobody is ".$ChatLaunch." at this time.");
require("./${ChatPath}/lib/connected_users.lib.php3");
display_connected($ShowPrivate,$DisplayUsers,($DisplayUsers? USERS_LOGIN : NB_USERS_IN),NO_USER);
When I creat a PHP page using that code the disired result is fine:
"User chatting at this time:
bill, billy, buzz" etc.
When I paste the same code into the forum area it just displays the code on the forum like so:
$ChatPath = "../mychat/chat/"; $ChatLaunch = "chatting"; $ShowPrivate = "0"; $DisplayUsers = "1"; define("NB_USERS_IN","users are ".$ChatLaunch." at this time."); define("USERS_LOGIN","User ".$ChatLaunch." at this time:"); define("NO_USER","Nobody is ".$ChatLaunch." at this time."); require("./${ChatPath}/lib/connected_users.lib.php3"); display_connected($ShowPrivate,$DisplayUsers,($DisplayUsers? USERS_LOGIN : NB_USERS_IN),NO_USER);
I'm pretty new to PHP and I'm stumped. Can anyone get me going in the right direction? Thank You.
if the file starts with
<?php
and end with?>, then everythin in between will run through the processor.
Many people do it different, by embedding little code snippets all over the file.
Example:
<html>
<body>
blabberblabber your name is: <?php echo $name;?>, pal.
Everything that's not enclosed by php brackets will show as-is - probably like your code.
</head>
<body>';
echo '
<div class="tborder" ', $context['browser']['needs_size_fix'] &&!$context['browser']['is_ie6']? ' style="width: 100%;"' : '', '>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="catbg" height="32">';
if (empty($settings['header_logo_url']))
echo '
<span style="font-family: Verdana, sans-serif; font-size: 140%; ">', $context['forum_name'], '</span>';
else
echo '
<img src="', $settings['header_logo_url'], '" style="margin: 4px;" alt="', $context['forum_name'], '" />';
echo '
</td>
<td align="right" class="catbg">
<img src="', $settings['images_url'], '/smflogo.gif" style="margin: 2px;" alt="" />
</td>
</tr>
</table>';
// display user name
echo '
<table width="100%" cellpadding="0" cellspacing="0" border="0" >
<tr>';
if($context['user']['is_logged'])
echo '
<td class="titlebg2" height="32">
<span style="font-size: 130%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '</b></span>
</td>';
// display the time
echo '
<td class="titlebg2" height="32" align="right">
<span class="smalltext">' , $context['current_time'], '</span>';
// this is the upshrink button for the user info section
echo '
<a href="#" onclick="shrinkHeader(!current_header); return false;"><img id="upshrink" src="', $settings['images_url'], '/', empty($options['collapse_header'])? 'upshrink.gif' : 'upshrink2.gif', '" alt="*" title="', $txt['upshrink_description'], '" align="bottom" style="margin: 0 1ex;" /></a>
</td>
</tr>
<tr id="upshrinkHeader"', empty($options['collapse_header'])? '' : ' style="display: none;"', '>
<td valign="top" colspan="2">
<table width="100%" class="bordercolor" cellpadding="8" cellspacing="1" border="0" style="margin-top: 1px;">
<tr>';
if (!empty($context['user']['avatar']))
echo '
<td class="windowbg" valign="middle">', $context['user']['avatar']['image'], '</td>';
echo '
<td colspan="2" width="100%" valign="top" class="windowbg2"><span class="middletext">';
// If the user is logged in, display stuff like their name, new messages, etc.
if ($context['user']['is_logged'])
{
echo '
<a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a> <br />
<a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a><br />';
}
// Otherwise they're a guest - send them a lovely greating...
else
echo $txt['welcome_guest'];
// Now, onto our second set of info, are they logged in again?
if ($context['user']['is_logged'])
{
// Is the forum in maintenance mode?
if ($context['in_maintenance'] && $context['user']['is_admin'])
echo '
<b>', $txt[616], '</b><br />';
// Are there any members waiting for approval?
if (!empty($context['unapproved_members']))
echo '
', $context['unapproved_members'] == 1? $txt['approve_thereis'] : $txt['approve_thereare'], ' <a href="', $scripturl, '?action=viewmembers;sa=browse;type=approve">', $context['unapproved_members'] == 1? $txt['approve_member'] : $context['unapproved_members'] . ' ' . $txt['approve_members'], '</a> ', $txt['approve_members_waiting'], '<br />';
// Show the total time logged in?
if (!empty($context['user']['total_time_logged_in']))
{
echo '
', $txt['totalTimeLogged1'];
// If days is just zero, don't bother to show it.
if ($context['user']['total_time_logged_in']['days'] > 0)
echo $context['user']['total_time_logged_in']['days'] . $txt['totalTimeLogged2'];
// Same with hours - only show it if it's above zero.
if ($context['user']['total_time_logged_in']['hours'] > 0)
echo $context['user']['total_time_logged_in']['hours'] . $txt['totalTimeLogged3'];
// But, let's always show minutes - Time wasted here: 0 minutes ;).
echo $context['user']['total_time_logged_in']['minutes'], $txt['totalTimeLogged4'], '<br />';
}
echo '
=============I WANT THE CODE TO GO HERE!=========
</span>';
}
// Otherwise they're a guest - this time ask them to either register or login - lazy bums...
else
{
echo '
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/sha1.js"></script>
<form action="', $scripturl, '?action=login2" method="post" class="middletext" style="margin: 3px 1ex 1px 0;"', empty($context['disable_login_hashing'])? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
<input type="text" name="user" size="10" /> <input type="password" name="passwrd" size="10" />
<select name="cookielength">
<option value="60">', $txt['smf53'], '</option>
<option value="1440">', $txt['smf47'], '</option>
<option value="10080">', $txt['smf48'], '</option>
<option value="302400">', $txt['smf49'], '</option>
<option value="-1" selected="selected">', $txt['smf50'], '</option>
</select>
<input type="submit" value="', $txt[34], '" /><br />
<span class="middletext">', $txt['smf52'], '</span>
<input type="hidden" name="hash_passwrd" value="" />
</form>';
}
echo '
</td>
</tr>
</table>
</td>
</tr>
</table>';
echo '=============I WANT THE CODE TO GO HERE!=========
everything after >echo '< will be shown as is, just the way you quoted it in your original post.
Dont place your code after the single quote of the echo - statement, but before echo or after the closing ' and ;
your code ..... ;
echo ' ........
....
...';
// Otherwise they're a guest - this time ask them to either register or login - lazy bums...
else
{
$ChatPath = "../mychat/chat/";
$ChatLaunch = "<A HREF=\"../mychat\chat\" TARGET=\"_self\">chatting</A>";
$ShowPrivate = "0";
$DisplayUsers = "1";
define("NB_USERS_IN","users are ".$ChatLaunch." at this time.");
define("USERS_LOGIN","User ".$ChatLaunch." at this time:");
define("NO_USER","Nobody is ".$ChatLaunch." at this time.");
require("./${ChatPath}/lib/connected_users.lib.php3");
display_connected($ShowPrivate,$DisplayUsers,($DisplayUsers? USERS_LOGIN : NB_USERS_IN),NO_USER);
echo '
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/sha1.js"></script>
=================================================
// Otherwise they're a guest - this time ask them to either register or login - lazy bums...
else
{
echo '
and;
$ChatPath = "../mychat/chat/";
$ChatLaunch = "<A HREF=\"../mychat\chat\" TARGET=\"_self\">chatting</A>";
$ShowPrivate = "0";
$DisplayUsers = "1";
define("NB_USERS_IN","users are ".$ChatLaunch." at this time.");
define("USERS_LOGIN","User ".$ChatLaunch." at this time:");
define("NO_USER","Nobody is ".$ChatLaunch." at this time.");
require("./${ChatPath}/lib/connected_users.lib.php3");
display_connected($ShowPrivate,$DisplayUsers,($DisplayUsers? USERS_LOGIN : NB_USERS_IN),NO_USER);
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/sha1.js"></script>