Web Analytics Made Easy -
StatCounter Help hyperlinking to a function - CodingForum

Announcement

Collapse
No announcement yet.

Help hyperlinking to a function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help hyperlinking to a function

    I've done lots of searching around, and havn't found any information on how to hyperlink to a function in another file,

    i'm using

    PHP Code:
    require( './functions_users.php');
    echo 
    "<a href='logout();'>"
    any thoughts?

  • #2
    You don't hyperlink to a function. You pass a parameter in the URL and then evaluate the parametere and then call the function.

    <a href="index.php?action=logout">Log Out</a>

    And then in index.php you would do something like:

    PHP Code:

    <?php

    function logout(){
        
    session_unset();
        
    session_destroy();
    }

    $action $_GET['action'];

    if(
    $action == "logout"){
        
    logout();
    }

    ?>
    Spookster
    CodingForum Supreme Overlord
    All Hail Spookster

    Comment


    • #3
      logout

      Thank you for helping me to understand,

      i appreciate it

      - Loren

      (ps: everything's working now)

      Comment


      • #4
        gahh

        Actually... for a while i've been trying to work with this... and it's not working for some reason

        i'm doing everything that it says... except for i have multipule functions in the file where that code goes and none of them work when i put it in... my link to the code is

        PHP Code:
        <?php

        echo"<a href='functions_users.php?action=Logout'>logout</a>";

        ?>

        Comment


        • #5
          You need to post the rest of the code.
          Spookster
          CodingForum Supreme Overlord
          All Hail Spookster

          Comment


          • #6
            I think you have to be more specific with your error analysis. What does not work where, and what was the expected behaviour?

            Anyway, in case you used the code Spookster gave you, you made one mistake: You are passing the parameter value "Logout" with a captial "L", but in the if-statement this value is compared against "logout" - that won't match, as these words differ in their first letter. To help that, you could lowercase all incoming GET values automatically:

            PHP Code:
            $_GET array_map('strtolower'$_GET);

            $action $_GET['action'];

            if(
            $action == "logout"){
             
            logout();

            Of couse you can also use strtolower() on a single variable, or do a case-insensitive string comparison with strcasecmp().
            Last edited by mordred; Feb 15, 2004, 07:07 AM.
            De gustibus non est disputandum.

            Comment


            • #7
              -_-

              Sorry, but i wasn't exactly useing his code... here is an example of what i used


              THIS is the file that includes the code i'm using to link to the file
              PHP Code:
              <a href='functions_users.php?action=Logout'>logout</a
              This is only a small portion of the file that includes my scripts many functions
              PHP Code:
              <?php
              include "db.php";

              /* ---------- Actions ---------- */
              $_GET array_map('strtolower'$_GET);

              $action $_GET['action'];

              if(
              $action == "Logout"){Logout();}


              function 
              Logout () {
                  
              session_start();
                  
              session_destroy();
                  if(!
              session_is_registered('name')){
                      echo 
              "<center><b>You are now logged out</b></center>";
                  }
              }


              function 
              Encrypt($string){
                  
              /* Hash then encrypt a string */
                  
              $crypted md5($string);
                  return 
              $crypted;
              }

              ?>

              I know that my php version is 4.3.1, and i'm still not sure why this isn't working... any ideas????

              Comment


              • #8
                Mordred already showed you why it wasn't working.

                $action == "Logout"

                logout != Logout
                Spookster
                CodingForum Supreme Overlord
                All Hail Spookster

                Comment

                Working...
                X