PHPSELF when used with file function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Murali

    PHPSELF when used with file function

    Hi,

    I have a php file, where i am using an include from a URL

    detail.php:

    $html = "";
    $contentFile = "http://www.mysite.com/link.php";
    if ( $contentFile ) {
    $fileBuffer = file($contentFi le);
    foreach ($fileBuffer as $tmp) {
    $html .= $tmp;
    }
    }

    ------------------------
    link.php contains a script which echos $PHP_SELF

    when i echo it, it displays "link.php" but i want the output as
    "detail.php " basically i need to echo where the link is called from..

    any solution ??

    thanks
    murali
  • Martin Meredith

    #2
    Re: PHPSELF when used with file function

    Why can't you use $PHP_SELF in detail.php ?

    Murali wrote:
    [color=blue]
    > Hi,
    >
    > I have a php file, where i am using an include from a URL
    >
    > detail.php:
    >
    > $html = "";
    > $contentFile = "http://www.mysite.com/link.php";
    > if ( $contentFile ) {
    > $fileBuffer = file($contentFi le);
    > foreach ($fileBuffer as $tmp) {
    > $html .= $tmp;
    > }
    > }
    >
    > ------------------------
    > link.php contains a script which echos $PHP_SELF
    >
    > when i echo it, it displays "link.php" but i want the output as
    > "detail.php " basically i need to echo where the link is called from..
    >
    > any solution ??
    >
    > thanks
    > murali[/color]

    Comment

    • Pedro Graca

      #3
      Re: PHPSELF when used with file function

      Murali wrote:
      [...][color=blue]
      > when i echo it, it displays "link.php" but i want the output as
      > "detail.php " basically i need to echo where the link is called from..
      >
      > any solution ??[/color]

      Don't read the file with file(). That way you are processing it as
      another page; instead simply include it

      <?php include 'link.php'; ?>

      --
      ..sig

      Comment

      • Murali

        #4
        Re: PHPSELF when used with file function

        Yah, but actually i need to add this html output of link.php to $html
        string and print it later...

        other thing which i thought is, i might pass a query string(file name)
        to link.php and read that in link.php

        like
        file("http://www.mysite.com/link.php?pg=/mypage.php")

        and in link.php i would refer to mypage.php.

        i actually tried this, but for some reason, my logic which was working
        is not working now.. :(

        i am actually expanding a menu and collapsing a menu by passing
        arguments.. something like menu=0 and menu=1.



        Pedro Graca <hexkid@hotpop. com> wrote in message news:<bonmlg$1f ni77$1@ID-203069.news.uni-berlin.de>...[color=blue]
        > Murali wrote:
        > [...][color=green]
        > > when i echo it, it displays "link.php" but i want the output as
        > > "detail.php " basically i need to echo where the link is called from..
        > >
        > > any solution ??[/color]
        >
        > Don't read the file with file(). That way you are processing it as
        > another page; instead simply include it
        >
        > <?php include 'link.php'; ?>[/color]

        Comment

        • Pedro Graca

          #5
          Re: PHPSELF when used with file function

          Murali wrote:[color=blue]
          > Yah, but actually i need to add this html output of link.php to $html
          > string and print it later...[/color]

          Make a function in link.php that returns what you need.

          [color=blue]
          > other thing which i thought is, i might pass a query string(file name)
          > to link.php and read that in link.php[/color]

          That should be a parameter to the function.

          [color=blue]
          > like
          > file("http://www.mysite.com/link.php?pg=/mypage.php")
          >
          > and in link.php i would refer to mypage.php.[/color]

          like
          <?php
          // ...
          require_once 'link.php';
          $html .= link_function(' mypage.php');
          // ...
          ?>

          [color=blue]
          > i actually tried this, but for some reason, my logic which was working
          > is not working now.. :(
          >
          > i am actually expanding a menu and collapsing a menu by passing
          > arguments.. something like menu=0 and menu=1.[/color]

          in link.php you can define the function with those parameters too:
          <?php
          function link_function($ page, $collapse=false ) {
          $retval = 'menu';
          if (!$collapse) $retval .= '<br/>submenu';
          return $retval;
          }
          ?>

          --
          ..sig

          Comment

          Working...