Solved

How do I get a php script to dynamically change.

Posted on 2014-07-31
5
317 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 108

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to create a scatter graph with straight lines 6 26
Hacked File Timestamps 4 49
html input type 3 22
compact pure CSS Read More Toggle 4 22
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.
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 …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
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 …

911 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

21 Experts available now in Live!

Get 1:1 Help Now