finding what page wanted to include

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

    finding what page wanted to include

    guys say if I include("anyfil e.php") into a file. Is it possible for me to
    access the calling page from anyfile.php.

    Can I do something like this for instance::

    if callingpage == "newauthor. php"
    then mysql(INSERT into author.....)
    else
    mysql(INSERT into content...)

    Thanks.
    --
    AKA Marketing.com - Internet Marketing (mainly)
    .NET blog with close to 300 posts on .NET ecosystem topics such as .NET, C#, Entity Framework, SQL Server, Visual Studio and Azure as well as miscellaneous software development topics.

    .NET blog with close to 300 posts on .NET ecosystem topics such as .NET, C#, Entity Framework, SQL Server, Visual Studio and Azure as well as miscellaneous software development topics.

    t : 353 - 87- 9807628 ||| e: contactATakamar keting.com


  • Stijn Verholen

    #2
    Re: finding what page wanted to include

    Dave wrote:[color=blue]
    > guys say if I include("anyfil e.php") into a file. Is it possible for me to
    > access the calling page from anyfile.php.
    >
    > Can I do something like this for instance::
    >
    > if callingpage == "newauthor. php"
    > then mysql(INSERT into author.....)
    > else
    > mysql(INSERT into content...)
    >
    > Thanks.[/color]

    Including a file doesn't "call" it.

    Create a function in anyfile.php,
    include anyfile.php in newauthor.php,
    call the function from newauthor.php

    Comment

    • J.O. Aho

      #3
      Re: finding what page wanted to include

      Dave wrote:[color=blue]
      > guys say if I include("anyfil e.php") into a file. Is it possible for me to
      > access the calling page from anyfile.php.
      >
      > Can I do something like this for instance::
      >
      > if callingpage == "newauthor. php"
      > then mysql(INSERT into author.....)
      > else
      > mysql(INSERT into content...)
      >
      > Thanks.[/color]

      $_SERVER['PHP_SELF'] will tell you which file has been called, this will
      include the path that has been given in the URL

      eg http://mydomain.net/some/path/myscript.php
      $_SERVER['PHP_SELF'] -> /some/path/myscript.php


      Another method would be using variables set in the page that calls your
      "anyfile.ph p"

      ---in your myscript.php---
      <?PHP
      $IS_AUTH=FALSE;
      include("anyfil e.php");
      ....
      --- eof ---

      ---in your newauthor.php---
      <?PHP
      $IS_AUTH=TURE;
      include("anyfil e.php");
      ....
      --- eof ---

      ---in your anyfile.php---
      <?PHP
      /* if you have more than 2 options, then
      * use a value insted of bool and use swtich()
      */
      if ($IS_AUTH) {
      $query="INSERT INTO author.....";
      } else {
      $query="INSERT INTO content...";
      }
      @mysql_query($q uery);
      ....
      --- eof ---

      Or you can do a function that you call from the main scripts

      ---in your anyfile.php---
      <?PHP
      function auto_insert($ta ble,$values) {
      /* $table is a string
      * $values is a string with the values to insert)
      */
      $query="INSERT INTO $table VALUES($values) ";
      @mysql_query($q uery);
      }
      ....
      --- eof ---

      <?PHP
      include("anyfil e.php");
      ....
      auto_insert("co ntent",$values) ;
      ....
      --- eof ---

      ---in your newauthor.php---
      <?PHP
      include("anyfil e.php");
      ....
      auto_insert("au thor",$values);
      ....
      --- eof ---

      So you have quite a lot of options, and it's all up to you how you want to do
      things...


      //Aho

      Comment

      • Chung Leong

        #4
        Re: finding what page wanted to include

        "Dave" <contact@akamar keting.com> wrote in message
        news:ct0att$r46 $1@kermit.esat. net...[color=blue]
        > guys say if I include("anyfil e.php") into a file. Is it possible for me to
        > access the calling page from anyfile.php.
        >
        > Can I do something like this for instance::
        >
        > if callingpage == "newauthor. php"
        > then mysql(INSERT into author.....)
        > else
        > mysql(INSERT into content...)
        >
        > Thanks.[/color]

        You can get that info from debug_backtrace (), I think. As others have
        suggested though, it's better to implement a function and use arguments to
        control its behavior.


        Comment

        Working...