Solved

How do I get a php script to dynamically change.

Posted on 2014-07-31
5
314 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 Richardson
  • 2
  • 2
5 Comments
 
LVL 58

Expert Comment

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

Author Comment

by:Mario Richardson
Comment Utility
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 250 total points
Comment Utility
It would make more sense to use
$_SERVER["DOCUMENT_ROOT"]

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

Accepted Solution

by:
Ray Paseur earned 250 total points
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Menu Inconsistent 3 19
Bootstrap 3 and Angular 2 12 21
sql sentence 2 10
File not deleting using unlink 6 0
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now