Welcome to Geeklog, Anonymous Monday, November 25 2024 @ 11:38 pm EST
Geeklog Forums
Will someone help with a PHP header.thtml issue?
Whoosh
Anonymous
I'm pretty new to PHP and need help. Can someone help me with this code?
I am trying to put some PHP code in header.thtml. If the user is logged in, I want to display a LOGOUT graphic in the header (and when the mouse goes over it I want the logout graphic to change). But if the user is logged out, I want a LOGIN graphic to display in the header (and when the mouse goes over it I want the login graphic to change).
Here is something like what I want, but I need the stuff between the if/else statements converted to PHP syntax.
<?php
if ($_USER['uid'] > 1) {
<td colspan=2> <a href="{site_url}/users.php?mode=logout"
onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('logoutover','','{layout_url}/images/logoutover.gif',1)">
<img name="logoutoff" src="{layout_url}/images/logoutoff.gif" width=48 height=29 border=0></a></td>
} else {
<td colspan=2> <a href="{site_url}/users.php?mode=login"
onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('loginover','','{layout_url}/images/loginover.gif',1)">
<img name="loginoff" src="{layout_url}/images/loginoff.gif" width=48 height=29 border=0></a></td>
}
?>
Is this even possible to do? Thanks for any help in understanding it. I've tried everything I know to do.
I am trying to put some PHP code in header.thtml. If the user is logged in, I want to display a LOGOUT graphic in the header (and when the mouse goes over it I want the logout graphic to change). But if the user is logged out, I want a LOGIN graphic to display in the header (and when the mouse goes over it I want the login graphic to change).
Here is something like what I want, but I need the stuff between the if/else statements converted to PHP syntax.
Text Formatted Code
<?php
if ($_USER['uid'] > 1) {
<td colspan=2> <a href="{site_url}/users.php?mode=logout"
onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('logoutover','','{layout_url}/images/logoutover.gif',1)">
<img name="logoutoff" src="{layout_url}/images/logoutoff.gif" width=48 height=29 border=0></a></td>
} else {
<td colspan=2> <a href="{site_url}/users.php?mode=login"
onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('loginover','','{layout_url}/images/loginover.gif',1)">
<img name="loginoff" src="{layout_url}/images/loginoff.gif" width=48 height=29 border=0></a></td>
}
?>
Is this even possible to do? Thanks for any help in understanding it. I've tried everything I know to do.
12
8
Quote
Whoosh
Anonymous
Hi Dirk:
I saw this thread. But you see I don't want to simply print the words. I want to display graphics that say login or logout.
Do I still need to use print? I'll try this and see what happens. Apologies for such dumb questions.
I saw this thread. But you see I don't want to simply print the words. I want to display graphics that say login or logout.
Do I still need to use print? I'll try this and see what happens. Apologies for such dumb questions.
5
9
Quote
Status: offline
Blaine
Forum User
Moderator
Registered: 07/16/02
Posts: 1232
Location:Canada
You need to use the php command echo or print since your new HTML is inside the PHP tags. Just entering HTML is not valid PHP.
This example is:
echo "<td>This is a <b>table</b> row</td>";
Geeklog components by PortalParts -- www.portalparts.com
This example is:
Text Formatted Code
echo "<td>This is a <b>table</b> row</td>";
Geeklog components by PortalParts -- www.portalparts.com
11
10
Quote
Whoosh
Anonymous
I think I understand. Thanks a lot Blaine. So it seems that when you use print or echo in this case, you are in a sense printing the html (conditionally) into the header.thtml script to be executed. I hope my understanding here is correct. I'll go buy a PHP book and stop asking such basic things here.
7
9
Quote
Status: offline
Blaine
Forum User
Moderator
Registered: 07/16/02
Posts: 1232
Location:Canada
That is correct. Just adding the echo or print with quotes should do it. You need to be carefull using single and double quotes. You need to quote the complete line you want to string that you want to echo but you will likely have quotes as well in that string.
So as an example. Use single quotes on the outside and double quotes on the inside.
echo '<a href="http://www.google.com">google</a>';
Alternatively you will see people escape the quotes so they are not interpreted by PHP as in:
echo "<a href=\"http://www.google.com\">google</a>";
Hopefully that helps.
Geeklog components by PortalParts -- www.portalparts.com
So as an example. Use single quotes on the outside and double quotes on the inside.
Text Formatted Code
echo '<a href="http://www.google.com">google</a>';
Alternatively you will see people escape the quotes so they are not interpreted by PHP as in:
Text Formatted Code
echo "<a href=\"http://www.google.com\">google</a>";
Hopefully that helps.
Geeklog components by PortalParts -- www.portalparts.com
10
7
Quote
Whoosh
Anonymous
Ah. Yes. Thanks so much. I also see that this can be tricky for the unitiated (like me ) when dealing with variables. Single quotes don't seem to alllow variable contents to display. Doubles do. So I am trying to follow the example I sometimes see in the GL code '(stuff here) "' . VARIABLE . '"(more stuff)'. That can get to be a bit maddening when dealing with long strings that contain variables.
Hey. This mini tutorial was really nice of you! It helps quite a lot.
Thanks!
Hey. This mini tutorial was really nice of you! It helps quite a lot.
Thanks!
8
9
Quote
Whoosh
Anonymous
Been all night at this. Need sleep. I have managed to take this:
<td colspan=2><a href="{site_url}/users.php?mode=logout" onMouseOut="MM_swapImgRestore()" </html></b>
and successfully translate it into this:
print '<td colspan=2><a href="' . $_CONF['site_url'] . '/users.php?mode=logout" onMouseOut="MM_swapImgRestore()"';
?></b>
That was easy because an example already existed of it. My problem is in trying to convert the following html lines into PHP:
<img name="buttonON" src="{button_path}/button.gif" width=48 height=29 border=0></a></td></b>
I can probably do the "img name" line, but the "onMouseOver" command above has taken everything out of me. Is it even possible to do it?
{button_path} is really {layout_path}.
Thanks for any help - from anyone...
Text Formatted Code
<b><html><td colspan=2><a href="{site_url}/users.php?mode=logout" onMouseOut="MM_swapImgRestore()" </html></b>
and successfully translate it into this:
Text Formatted Code
<b><?phpprint '<td colspan=2><a href="' . $_CONF['site_url'] . '/users.php?mode=logout" onMouseOut="MM_swapImgRestore()"';
?></b>
That was easy because an example already existed of it. My problem is in trying to convert the following html lines into PHP:
Text Formatted Code
<b>onMouseOver="MM_swapImage('buttonON','','{button_path}/ButtonON.gif',1)"><img name="buttonON" src="{button_path}/button.gif" width=48 height=29 border=0></a></td></b>
I can probably do the "img name" line, but the "onMouseOver" command above has taken everything out of me. Is it even possible to do it?
{button_path} is really {layout_path}.
Thanks for any help - from anyone...
11
6
Quote
All times are EST. The time is now 11:38 pm.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content