By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,823 Members | 756 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,823 IT Pros & Developers. It's quick & easy.

finding what page wanted to include

P: n/a
guys say if I include("anyfile.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)
http://www.akamarketing.com/hosting
http://www.akamarketing.com/webmaster-forums
t : 353 - 87- 9807628 ||| e: contactATakamarketing.com
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Dave wrote:
guys say if I include("anyfile.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.


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
Jul 17 '05 #2

P: n/a
Dave wrote:
guys say if I include("anyfile.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.


$_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.php"

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

---in your newauthor.php---
<?PHP
$IS_AUTH=TURE;
include("anyfile.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($query);
....
--- eof ---

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

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

<?PHP
include("anyfile.php");
....
auto_insert("content",$values);
....
--- eof ---

---in your newauthor.php---
<?PHP
include("anyfile.php");
....
auto_insert("author",$values);
....
--- eof ---

So you have quite a lot of options, and it's all up to you how you want to do
things...
//Aho
Jul 17 '05 #3

P: n/a
"Dave" <co*****@akamarketing.com> wrote in message
news:ct**********@kermit.esat.net...
guys say if I include("anyfile.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.


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.
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.