Solved

How do I get a php script to dynamically change.

Posted on 2014-07-31
5
320 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
  • 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 250 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 109

Accepted Solution

by:
Ray Paseur earned 250 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 109

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

777 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