set constant in html page

Hi Experts!

I am trying to modify an existing internal html file, which uses HTML 4.0 Transitional - not sure if more information is needed about my environment.  

Right now several links point to the dev server, but when I move the file to prod, I want to update the server name in a single location instead of within each href value.

For example, a link points to \\dev_server\myfiles\myfile.txt.  How do I set a constant at the top of the file with the server name that can be referred to as part of the href value?  

Then instead of having to replace each instance of \\dev_server\myfiles\myfile.txt with \\prod_server\myfiles\myfile.txt, I could just use \\[server_instance]\myfiles\myfile.txt throughout and update the [server_instance] constant with the appropriate value.

As an alternative, PHP is also installed on the servers, but I don't know which version, I just know that there are some existing files that have php and html intermixed.  I don't know very much php, but how could I php to set the value of a constant, and then use that constant within the HTML?

Or maybe you have a better idea for a simple solution?  (My options are limited at the moment, so I can't use, for example, javascript.)  

My skills are with database development and I'm very, very new to html and php.
tancatOracle DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark BullockQA EngineerCommented:
You can use relative links instead of absolute.

For example if your user is browsing http://www.yourdomain.com/page.html,
relative links on that page can be like this:
<a href="/myfiles/myfile.txt">linktext</a>

Open in new window


That would be the equivalent of http://www.yourdomain.com/myfiles/myfile.txt

This is assuming the files you want to link to are on the web server.
0
tancatOracle DeveloperAuthor Commented:
Unfortunately no, the files start out on the database or app server, which are dev, test, and prod.  The html file is the only thing on the web server.
0
Chris StanyonWebDevCommented:
Doing it with PHP is very easy. You'd need to rename the file to use a .php extension instead of .html

At the top of your page, add this:

<?php $server = "dev_server" ?>

And then to use it throughout your HTML, just echo it out:

\\<?php echo $server ?>\myfiles\myfile.txt
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

tancatOracle DeveloperAuthor Commented:
Ah, ok, I hadn't realized that I could use echo; I think I was looking for some kind of concatenation function between the constant and the rest of the path.  I'll try it out and see what happens.  

Just out of curiosity, what would be a more correct or technically mature way to solve this problem?  I have a feeling I'm dealing with some politics to which I'm not privy.
0
Chris StanyonWebDevCommented:
That's a pretty standard way of using variables in a file, and it doesn't really get much simpler.

A more 'proper' way of doing it would be to define a constant in a separate file, and then include that file on your page (or all of your pages). By convention, constants are named using all uppercase.

Create a file called settings.php:

<?php
define('SERVER', 'dev_server');

Open in new window


Then in your pages, require the settings file at the beginning of each document:

<?php require('settings.php') ?>

Open in new window


And just echo out the constant when you need to:

<p>The value of the SERVER constant is <?php echo SERVER ?></p>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tancatOracle DeveloperAuthor Commented:
I have tried but this does not work for me.  However, the file that I'm working with is kind of a mess; lots of old stuff, with no one cleaning it up between changes.  I'm going to start with a clean set of files and see if I can get this working.

In a couple of hours I'm going to submit another question related to passing information from this html file (which I think you said should be renamed as .php in order to use your solution above) to a batch file.
0
Chris StanyonWebDevCommented:
No worries tancat.

In order for the PHP to be interpreted properly, you'll need to change the extension to php. You'll also need to make sure that PHP is installed and running properly on your server.

Easiest way to check php is to create a simple file, call it pi.php with the following content:

<?php phpinfo();

Open in new window


Upload it to the root of your server and browse to it. If PHP is up and running, you'll see a screen containing all the config details of your PHP set up - don't leave this file on a production server - it can be a security risk!
0
tancatOracle DeveloperAuthor Commented:
Oh, of course; php is installed on the production server but probably not on the one I'm using for development.  No problem; I need to create a proper dev environment anyway, and I'll give it a try.  Thanks!
0
tancatOracle DeveloperAuthor Commented:
Thank you, Chris.  This worked perfectly.  And thanks for the tip about deleting the pi.php file; I did not realize that was a security risk.
0
Chris StanyonWebDevCommented:
No worries.

The reason it's a security risk is simply that when run it displays a lot of information about your server. A potential hacker could use that to find vulnerabilities in your systems.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.