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?
 
Chris StanyonCommented:
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
 
Mark BullockQA Engineer IIICommented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Chris StanyonCommented:
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
 
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
 
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 StanyonCommented:
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 StanyonCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.