Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

How do I get a php script to dynamically change.

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
Mario J. Richardson
Asked:
Mario J. Richardson
  • 2
  • 2
2 Solutions
 
GaryCommented:
Not sure I'm following you - whatever folder the script is in is the working folder
0
 
Mario J. RichardsonHealthcare AnalystAuthor Commented:
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
 
GaryCommented:
It would make more sense to use
$_SERVER["DOCUMENT_ROOT"]

And any folder paths to that for your home.php
0
 
Ray PaseurCommented:
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
 
Ray PaseurCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now