This is a general question. What are some techniques you employ to prevent the links in your PHP code from breaking every time you move a file or move a file into a different directory?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For front end stuff, always use absolute URLs (start with ‘/’ so you can move from domain to domain as needed).
For internal
include()/require()type stuff, do as Gaurav suggests and use a config file that creates a constant to represent your path (so you can change it easily as needed from one location in your code).For library type stuff (i.e. classes, functions, etc) that you want to reuse, I would add that to the
include_patheither via php.ini (global or local), .htaccess (if you are using apache) or via theini_set()function. That way you can include these files by just the filename (i.e.<?php include_once('library.php'); ?>)If you go the ini_set route, take a look at the auto_append directive (which in turn can be set via php.ini, .htaccess or ini_set)… that way you can have a ‘bootstrap’ file added to every page request that sets up your include_path for just that application without having to add the ini_set statement every where you turn.
With all that said, I recommend that you:
Good luck!