Jump to content

Best way to add a PHP element to an HTML page?


Lady_452

Recommended Posts

Ok I'm a n00b yada yada (lol)...

 

I have a .htm page on which I want to add a PHP script that will display links depending on if the user is in session or not. I'm not sure if this can be done on a strictly .htm page, but hey you only live once right?  Here's the script I'm attempting to execute:

 

  <? if ($_SESSION['auth'] == "yes"){ ?>

      <a href="/index.php?page=sign_in">Sign In</a>

            <? }else{ ?>

      <a href="index.php?page=logout">Logout</a>

  <? } ?>

 

The problem is that I don't know all the back-end php coding for the 3rd party s/w I'm using, but since the design calls for a "main .htm page" that displays all the "include" pages, having 2 links displaying on the same page seems silly (1 link for login and anohter for logout). 

 

So how can I combine these links and have them display depending on the session state of the user?  Or is there a better way of accomplishing this all together?  Thanks much for any help given.

 

 

Link to comment
Share on other sites

I'm not following why you want the page to say htm either but you could make the page say .taco if you wanted to, but if the web server isn't set up to know that taco is an alias for php it won't work. You can't just use a standard old html page to run php.

 

I think you simply have the links setup backwards the following will show logout if the session variable auth equals yes (I assume that means logged in.). Then if it doesn't equal yes it will provide the Sign In link.

 

   <? if ($_SESSION['auth'] == "yes"){ ?>
         <a href="index.php?page=logout">Logout[/url]
             <? }else{ ?>
       <a href="/index.php?page=sign_in">Sign In[/url]
  <? } ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.