embed php within an HTML hyperlink

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Greg Crowe
    New Member
    • Jul 2011
    • 2

    embed php within an HTML hyperlink

    This is the code for the hyperlink on a web page.
    <li class="current_ page_item" ><a href="</p>http://active.com">Log out</a></li>

    How do I add php code to be executed when "Logout" is clicked. I've tried adding the php code, but it continually executes the php code when the page is loaded.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    PHP is for before it reaches the client. Which is why it is called a server side language. For something to happen on the client side, you need to use a client side language, i.e. javascript.

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      To log a user as 'out', you'd typically point that anchor (the <a>) at a PHP page that does the processing. Something like:

      Code:
      // Some HTML file
      <a href="logout.php">Log Out</a>
      
      // logout.php
      <?php
      $user->logOut();
      ?>

      Comment

      • Greg Crowe
        New Member
        • Jul 2011
        • 2

        #4
        thanks for instruction. That worked. Here's the logout.php file I created.

        <?php
        //start session
        session_start() ;

        //remove session variables
        session_unset() ;

        // destroy the session
        session_destroy ();

        ?>
        Last edited by Greg Crowe; Jul 15 '11, 07:57 PM. Reason: I figured out my problem

        Comment

        Working...