realnsleo Posted May 17, 2009 Share Posted May 17, 2009 hello everyone .. i am pretty new to php programming and web development and i need to ask this. i have designed a few websites for my clients and i am getting better and now i have started learning php to add dynamic feel to the websites. my question is whenever i create links in my pages i do something like <a href="index.php">HOME</a>, <a href="aboutUs.php">ABOUT US</a> and so on. So i uploaded the website and whenever i view the source code the links appear exactly like that yet in other professional websites i have seen i always see something like <a href="http://www.facebook.com/home.php">HOME</a> for example. what am i doing wrong. how can i make better links to other pages. what is the use of building links in that format. thank you. Quote Link to comment https://forums.phpfreaks.com/topic/158500-please-help-with-links/ Share on other sites More sharing options...
BK87 Posted May 17, 2009 Share Posted May 17, 2009 you can try... <A href="http://<?= $_SERVER['SERVER_NAME']/file.php">open file.php</a> Quote Link to comment https://forums.phpfreaks.com/topic/158500-please-help-with-links/#findComment-835888 Share on other sites More sharing options...
realnsleo Posted May 17, 2009 Author Share Posted May 17, 2009 thanx a bunch. that helped. does it work for subdomains too? am guessing <a href="subdomain.<?= $_SERVER['SERVER_NAME']/file.php">FILE</a> Quote Link to comment https://forums.phpfreaks.com/topic/158500-please-help-with-links/#findComment-835902 Share on other sites More sharing options...
wildteen88 Posted May 17, 2009 Share Posted May 17, 2009 The subdomain will be part of SERVER_NAME Quote Link to comment https://forums.phpfreaks.com/topic/158500-please-help-with-links/#findComment-835910 Share on other sites More sharing options...
realnsleo Posted May 17, 2009 Author Share Posted May 17, 2009 wait, sorry i am not understanding. okay i got a couple of more questions. let's say i have purchased a domain called www.mydomain.com and there are a couple of files under this domain like index.php, aboutus.php and contactus.php, then i create a subdomain called sub.mydomain.com where i save some php files for example a script that sends mail. so in the form on the contactus.php what will i place on the action ie <form method="post" action="?"> another question is in my website i have some php configuration files like the database connection and other scripts that perform important functions. however when i try to require a php file into one of my php pages i get an error. why is that and how can i include or require php files easily. eg require("http://mydomain.com/phpfiles/myphpfile.php"); // does not work thanks for all the help. Quote Link to comment https://forums.phpfreaks.com/topic/158500-please-help-with-links/#findComment-835915 Share on other sites More sharing options...
wildteen88 Posted May 17, 2009 Share Posted May 17, 2009 You should not be using http:// to include/require files. You should be using local file paths require($_SERVER['DOCUMENT_ROOT'].'/phpfiles.myfile.php'); Quote Link to comment https://forums.phpfreaks.com/topic/158500-please-help-with-links/#findComment-835916 Share on other sites More sharing options...
realnsleo Posted May 17, 2009 Author Share Posted May 17, 2009 oh i see.. thanks .. so is it a good idea to keep php files out of the www directory? my web host directory is like this - mydomain.com -.cpanel -.htpasswds -.access_logs -.etc -.public_ftp -.public_html -.tmp -.www is it more secure to create a directory for my php files outside the www directory and call them using <?php $_SERVER["DOCUMENT_ROOT"]."/myDirectory/myfiles.php"; ?> as you mentioned? Quote Link to comment https://forums.phpfreaks.com/topic/158500-please-help-with-links/#findComment-835930 Share on other sites More sharing options...
BK87 Posted May 17, 2009 Share Posted May 17, 2009 it really dosen't matter, it saves you a step... I usually keep files like config.php a directory back from www just in case file associations might get screwed up, other code can/should be kept in www dir. Quote Link to comment https://forums.phpfreaks.com/topic/158500-please-help-with-links/#findComment-835940 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.