Pre-Defined Variable For Calling PHP File.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eros
    New Member
    • Jun 2007
    • 66

    Pre-Defined Variable For Calling PHP File.

    [PHP]//page1.php
    <?php
    include('pageba se.php');
    ?>

    //pagebase.php
    <?php
    echo __CALLING_FILE_ _; // outputs the previous php file. 'page1.php'
    ?>[/PHP]

    I dont know the equivalent of __CALLING_FILE_ _. Please let me know on how to determine the previous file or the calling file.
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    What language is __CALLING_FILE_ _ from...? And what is it that you are trying to do?

    Comment

    • eros
      New Member
      • Jun 2007
      • 66

      #3
      Originally posted by volectricity
      What language is __CALLING_FILE_ _ from...? And what is it that you are trying to do?
      __CALLING_FILE_ _ is not a PHP code.. I put that for example... I am searching for similar functionality.. . a Pre-Defined of PHP that gives the parent or the calling php file...in order to determine who was called the pagebase.php.. and use it into conditional statement for different processes..

      [PHP]<?php
      //pagebase.php
      switch ( __CALLING_FILE_ _ ) {
      case "index.php" :
      //codes here if index.php is the calling php file.
      break;
      case "page1.php" :
      //codes here if page1.php is the calling php file.
      break;
      case........... ..
      //codes here if ????.php is the calling php file.
      break;......... .
      }
      ?>[/PHP]

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        Yeah, that's not possible, but it's halfway senseless, anyway.

        You do know that you can attach a query string when including a file, right? Maybe you could add this to your includes:

        [php]include 'foo.php?callin gFile=' . basename(__FILE __);[/php]

        Then check $_GET['callingFile'] in the included file.

        Comment

        • eros
          New Member
          • Jun 2007
          • 66

          #5
          Originally posted by volectricity
          Yeah, that's not possible, but it's halfway senseless, anyway.

          You do know that you can attach a query string when including a file, right? Maybe you could add this to your includes:

          [php]include 'foo.php?callin gFile=' . basename(__FILE __);[/php]

          Then check $_GET['callingFile'] in the included file.
          Yes that's it, but unfortunately i got an error Failed opening required
          [PHP]require_once '../phpbase.php?cal lingFile=' . basename(__FILE __);[/PHP]

          Comment

          • eros
            New Member
            • Jun 2007
            • 66

            #6
            [PHP]<?php
            include '../phpbase.php?var =1';
            //............... ..
            ?>[/PHP]

            Error Message: failed to open stream: Invalid argument

            Comment

            • kovik
              Recognized Expert Top Contributor
              • Jun 2007
              • 1044

              #7
              Then you'll need to create a more sensible program flow. What is it that you are trying to do....?

              You could try using defined constants.

              [php]// page1.php
              define('PAGE1', true);[/php]

              [php]// page2.php
              if(defined('PAG E1'))
              {
              ...
              }[/php]

              Comment

              • eros
                New Member
                • Jun 2007
                • 66

                #8
                Originally posted by volectricity
                Then you'll need to create a more sensible program flow. What is it that you are trying to do....?

                You could try using defined constants.

                [php]// page1.php
                define('PAGE1', true);[/php]

                [php]// page2.php
                if(defined('PAG E1'))
                {
                ...
                }[/php]
                In page1.php was done well but in page2.php, when passed through to if(defined('PAG E1')), "Constant PAGE1 already defined" was noticed. Returns false value.

                Comment

                • kovik
                  Recognized Expert Top Contributor
                  • Jun 2007
                  • 1044

                  #9
                  Originally posted by eros
                  In page1.php was done well but in page2.php, when passed through to if(defined('PAG E1')), "Constant PAGE1 already defined" was noticed. Returns false value.
                  Sounds like you made a typo.

                  Comment

                  Working...