473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

finding what page wanted to include

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
3 1591
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David Berry | last post by:
Hi All. I'm trying to write an ASP page that shows me the UNIQUE account number for a customer (so I can pass it to another page) based on a search criteria. For example, I want to do a select...
6
by: laura | last post by:
I'm doing a page which gathers some text in the form of a text box in a <form>. This text is saved to a text file, notices.txt and I want to be able to display the saved text on the page, as soon...
4
by: Dave Farrance | last post by:
What's the correct way to find the include directories and link libraries when compiling with gnu c++ ? I decided that I'd like to try out line-drawing using the GTK toolkit, so I copied the...
3
by: KL | last post by:
Well, I am back. This time our assignment has us filling a vector and then timing how long it takes to find a spot in the vector to insert a new item, and the time required to insert the item...
6
by: John Sedlak | last post by:
Hello, in one of my pages I have an include: <!--#include file="console.aspx" --> Now...Inside console.aspx, I want to be able to find the name of the page that included it. This is because I...
2
by: Alex Maghen | last post by:
I want to create a utility function that will seach the current page for one of my UserControls by it's type. So, let's say that I have a UserControl whose class I defined as follows: namespace...
2
by: CM | last post by:
Hi, Could anyone please help me? I am completing my Master's Degree and need to reproduce a Webpage in Word. Aspects of the page are lost and some of the text goes. I would really appreciate it....
42
by: smerf | last post by:
Using javascript, is there a way to trap an external page inside a frame? I've seen scripts to break out of frames, but nothing to keep a page trapped in a frame.
25
by: Daniel Kraft | last post by:
Hi, I do need to implement something similar to C++'s std::bitset in C; for this, I use an array of int's to get together any desired number of bits, possibly larger than 32/64 or anything like...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.