?
Solved

How do I get a php script to dynamically change.

Posted on 2014-07-31
5
Medium Priority
?
327 Views
Last Modified: 2014-08-25
How do I get a php script to dynamically change. Example I am trying to test my php files on a prod-server.
In the inetpub/wwwroot on the server I have the following folders.
Dev_Main
Upgrade_Main
Main
In each of these folders I have sub-directories.
What do I need to put in my code to let the php know regardless of where it resides it should stay in the folder and sub directory that it is being called from.
The only time I want to jump out of that sub-directory is if I am trying to return to home which would be a php in another sub-directory.

<html>
<title>Upgrade Add Employer</title>
<head>
<?php
//INCLUDE THE NECESSARY FILES
require_once("c:/php/pear/configtest.php"); 
require("c:/php/pear/functions.php");
?>
<base href="<?php echo HTTP_SERVER; ?>">
<link rel="stylesheet" type="text/css" href="\images\webapps.css" />
<?php 
$containing_dir = basename(dirname(__FILE__));
$folder=(substr(substr(getenv('SCRIPT_NAME'),1),0,stripos(substr(getenv('SCRIPT_NAME'),1),"/")));
if (isset($_COOKIE['USERID'])==false)
{
if (isset($_COOKIE['Upgrade_MAIN']))
{echo("<script language=JavaScript>window.location.href='/<?=$containing_dir?>/Home.php?error=1';</script>");}
else
{echo("<script language=JavaScript>window.location.href='/<?=$containing_dir?>/Employer_Home.php?error=1';</script>");}
}
?>
 


</head>
<body>
<?php echo $folder; ?>
<form name="AddEmployer" method="post" action='\<?php echo $folder?>\Employer_ConfirmAdd.php'>
<div id='container'>
<table cellspacing="1" cellpadding="1" width='100%'>
<tr>
<td width="25%" valign="top">
<table>

<?php 
if (isset($_COOKIE['Upgrade_MAIN']))
{("<tr><td align='center'><a href='./Menu.php' target='_top'><IMG SRC='\images\LOGO_(100).bmp' border='0' alt='Home'></a><BR><!--<B>Care<BR>Home</B></font><BR>--><HR></td></tr>");}
else
{("<tr><td align='center'><a href='\<?php echo $folder?>\Menu.php' target='_top'><IMG SRC='\images\LOGO_(100).bmp' border='0' alt='Home'></a><BR><HR></td></tr>");}
?>
<tr>
<td>Add Employer</td>
</tr>
<tr>
<td><a href='/<?php echo $folder?>/Employer_FrameSet.php'>Search Employer</a></td>
</tr>

<?php 
if (isset($_COOKIE['Upgrade_MAIN']))
{echo("<tr><td><a href='$folder/Home.php'?Logoff=yes>Log Off</a></td></tr>");}
else
{echo("<tr><td><a href='$folder/Home.php'?Logoff=yes>Log Off</a></td></tr>");}
?>
</table>
</td>
<td>
<table cellspacing="1" cellpadding="1" width="70%" align="center">
<tr>
<td align="center"><font size=-10><IMG SRC="/images/UPGSiteLogo.bmp" align="middle"></font></td></tr>
<tr><td align="center"><h1>Add New Employer</h1></td></tr>


<tr>
<td align="center"><font color="red">*</font> denotes required field</td>
</tr> 
</table>

<table cellspacing="1" cellpadding="1" width="65%" align="center">
<tr class='headers'>
<td colspan="4"><br>Code</td>
</tr>
<tr>
<td colspan="4"><input type="text" disabled value="New"></td>
</tr> 
<tr class='headers'>
<td colspan="2">Employer Name <font color="red">*</font> <br></td>

</tr> 
<tr>
<td colspan="2"><input type="text" name="Name" value="" size="40" maxlength="30"</td>

</tr> 


<tr class='headers'>
<td colspan="2">Address 1<br>

<input type="text" name="Address1" value="" size="40"></td>

<td colspan="2" class='headers'>Address 2<br>


<input type="text" name="Address2" value="" size="40"</td>
</tr> 
<tr class='headers'>
<td colspan="2">City<br>
<input type="text" name="City" value="" size="25"></td>


<td>State<br>


<input type="text" name="State" value="" size="2" maxlength="2" onBlur="javascript:ValidateStateFormat(document.AddEmployer.State)"></td>


<td align="left">Zip/Postal Code<br>


<input type="text" name="Zip" value="" size="10" maxlength="10"></td>
</tr>
<tr class='headers'><td>Phone<br>
<input type="text" name="Phone" value="" size="15" onBlur="javascript:formatPhone(document.AddEmployer.Phone)"></td>
<td align="left">Fax<br>
<input type="text" name="FaxNo" value="" size="15" onBlur="formatPhone(document.AddEmployer.FaxNo)"></td>
</tr> 

<tr>
<td colspan="2"><br><input class='btnsave' type="submit" name="AddEmployer" value="Add Employer"></td>
</tr>

</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Open in new window

0
Comment
Question by:Mario J. Richardson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40232319
Not sure I'm following you - whatever folder the script is in is the working folder
0
 

Author Comment

by:Mario J. Richardson
ID: 40232658
Sorry I should have pointed what I needed more clearly.  If you look at line 45 in the code I have a reference that knows to look for the php in the current folder that it resides in.

Now if you look at line 50 and 52 I have those coded with the same variable as line 45 but what truly should happen at line 50 and 52 is it should look in another folder (stepping out of the current directory) to get the home.php

So line 45 is c:\inetpub\wwwroot\Upgrade_B and 50 and 52 are c:\inetpub\wwwroot\Upgrade_Main.  But I dont want to hardcode the name of the directories for it to traverse properly.  So that way when I copy the code to the c:\inetpub\wwwroot\B and c:\inetpub\wwwroot\Main there will be nothing needed to due because everything will not be hardcoded it will dynamically know what to do.

Hoping that is clearer???
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 750 total points
ID: 40232774
It would make more sense to use
$_SERVER["DOCUMENT_ROOT"]

And any folder paths to that for your home.php
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 750 total points
ID: 40232950
Two ideas.  First, learn about HEREDOC notation.  It will make your HTML templates much more workable.  Heed, but do not be put off by the warning.
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Second, use relative addressing.  If a script is in directory "X" and you create a link to "test.php" the resolved path will be root/X/test.php  Easy!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40283333
Please see the E-E grading guidelines, shown here:
http://support.experts-exchange.com/customer/portal/articles/481419

Why the marked-down grade?
0

Featured Post

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question