|
|
#1 | |
|
Registered User
Join Date: Mar 2004
Posts: 15,486
|
im getting into php and plan to use it for managing a MySQL database and some other things. (adding permissions, login control, email mailing list, activity log, etc.)
im looking to make a standard function for adding entries to the database. i shouldnt have a problem creating the function. however, is it possible for me create the function in a location and then access it from other .php files, or do i have to write the function into each php file? the latter sounds like a waste of space as well as extra time spent processing the page. anyone know how to reference functions in another .php file? |
|
|
|
|
|
|
#2 | |
|
Registered User
Join Date: Jul 2005
Posts: 3,606
|
Sure, simply create a separate page called "functions.php" and on each PHP page where you require the use of the function issue the following:
require("functions.php"); It's really that easy. ![]() Remember, any time you pass a variable to MySQL make sure you mysql_escape_string() first to avoid the possibility of SQL injection attacks. |
|
|
|
|
|
|
#3 |
|
Join Date: Jul 2004
Location: MKE
Posts: 13,629
|
I <3 includes
![]() ViN you're putting your security/login session checks as an include file as well, right? |
|
|
|
|
|
#4 | ||
|
Registered User
Join Date: Mar 2004
Posts: 15,486
|
Quote:
that's awesome.Quote:
ill be back here when i need help with preventing SQL injection attacks. thx guys ![]() |
||
|
|
|
|
|
#5 |
|
Registered User
Join Date: Jul 2005
Posts: 3,606
|
Post you're code, we'd be happy to review it with you especially for security concerns/etc.
|
|
|
|
|
|
#6 | |
|
Ngemu Mod
Join Date: Jul 2003
Location: Fresno, CA
Posts: 1,886
|
Quote:
require_once('functions.php'); ?
__________________
[i7 2600k @4.4ghertz][2x4 GB DDR3 1600][EVGA GTX570 1.280GB SC][EVGA GTX460 physx][Asrock Extreme7 Gen3 Z68][2xSeagate 160 Gb SATA HD raid0][Seagate 250 GB SATA2 HD][Sony Bravia 40' 1080p LCD HDTV][NEC 3520a DVD+-DLw][Windows 7 Ultimate x64][Rosewill 1000w] |
|
|
|
|
|
|
#7 | |
|
2JZ powered
|
Quote:
__________________
|
|
|
|
|
|
|
#8 | |
|
Registered User
Join Date: Jul 2005
Posts: 3,606
|
Quote:
|
|
|
|
|
|
|
#9 |
|
Registered User
Join Date: May 2007
Posts: 34
|
In practice, I usually use require/include_once() just in the event the chain of them end up referencing them multiple times. Solves a lot of "function redefined" statements.
|
|
|
|
|
|
#10 | |
|
Ngemu Mod
Join Date: Jul 2003
Location: Fresno, CA
Posts: 1,886
|
Quote:
All objects(classes) are defined on different php scripts: Object 1 requires object2; Object 3 requires object2; Your page requires object1, object2, and object3. Using only require('xx.php') would cause errors. I guess it would depend on what you're trying to do though.
__________________
[i7 2600k @4.4ghertz][2x4 GB DDR3 1600][EVGA GTX570 1.280GB SC][EVGA GTX460 physx][Asrock Extreme7 Gen3 Z68][2xSeagate 160 Gb SATA HD raid0][Seagate 250 GB SATA2 HD][Sony Bravia 40' 1080p LCD HDTV][NEC 3520a DVD+-DLw][Windows 7 Ultimate x64][Rosewill 1000w] |
|
|
|
|
|
|
#11 | |
|
Registered User
Join Date: Jul 2005
Posts: 3,606
|
Quote:
|
|
|
|
|
|
|
#12 |
|
Registered User
Join Date: Jul 2002
Posts: 374
|
If you're using PHP5, I'd suggest putting that core code into a class, and then putting the class file somewhere in your autoinclude path. That way, you don't need to require() or include() it, or worry about instantiation issues from other files.
A call like: $sess = new SessionHandler(); will look in your autoinclude path for a file named SessionHandler.php, read it in if it's not already instantiated, and call it. Putting the code in classes also keeps variable scoping a little cleaner plus a few other nice freebies. Using classes had a bit too much overhead in PHP4, but they are great in 5.
__________________
OCZ 2GB DDR400 Gold XTC RAM º Dual Samsung Spinpoint 250GB Sata HDDs in RAID 0 Aspire X-QPACK case w/Enermax EG425P-VE PSU º Liteon Dual Layer DVD Burner º Dual Dell FP 2001 20" LCD |
|
|
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| One more question... | soundview00 | NVIDIA Linux | 1 | 10-02-02 05:31 PM |
| 1st post - XP Restore question | Needa916 | Microsoft Windows XP And Vista | 2 | 09-12-02 05:24 PM |
| Newby question about nforce.... | superconti | NVIDIA Linux | 2 | 09-07-02 11:46 PM |
| Dual boot question.. | Tactics | General Hardware | 15 | 09-07-02 10:39 AM |
| Nvidia Driver Rpm Question | Big Booger | NVIDIA Linux | 17 | 08-11-02 12:55 PM |