0

What I am trying to do is put all of my variables in an external php file and then call them on different pages. I am creating workflows for multiple projects, all of these projects follow the same flow but have some different information like phone numbers and fees for things. So what I am trying to accomplish is put all of my variables in an external file so if something changes for a project I can edit the one file versus open up the 23 different workflows I have created.

This is just a sample of all the external file will have but for 31 different projects and 14 different variables for each.

<?php
$project_id = $_GET["project_id"];

switch ($project_id) {
case "fl":
    $title = "Florida EPC";
    $replacement_fee = "$4";
    break;
case "tx":
    $title = "Texas EPC";
    $replacement_fee = "$6";
    break;
}
?>

Then just a basic rundown of each workflow

<div id='a1' style="display:block;">
<div align="center" style="border-bottom: 1px solid black;">
<b>Check the CARDS tab for the PAN.</b><br /><br />

</div>
&nbsp;
 <div align="center">
<p><i>"I'm sorry to hear you have lost your card. I can cancel the Lost card for your protection."</i></p><br><br>
 <font color="red">Was the PAN issued?</font><br /><br />
<a class="button" href="javascript:switchid('a2');"><span>Yes</span></a>&nbsp;&nbsp;
<a class="button" href="javascript:switchid('a3');">No</a>
</div>
</div>

<div id='a2' style="display:none;">
<div align="center">
<p><b>Advise the client the card was previously cancelled.</b></p>
<p><i>"Your card has already been deactivated as of (date of deactivation)."</i></p>    <br><br>
<font color="red">Is the address up to date?</font><br /><br />
<a href="javascript:switchid('a4');">Yes</a>&nbsp; &nbsp;
<a href="javascript:switchid('a5');">No</a>
</div>
</div>

within some of the divs all i will put is <?php echo $avariable; ?> when the different info will be used. I just need to beable to call the external file on each workflow and can't figure that part out.

3 Answers 3

3

what you need is the require_once statement.

More info at http://php.net/manual/en/function.require-once.php

require_once can be used at the top of all of your pages and will only include the file a single time even when includes are nested.

Sign up to request clarification or add additional context in comments.

6 Comments

OR as they are required variables require_once()
agreed, require_once is better for @brock029 case
Ok so next problem is, I have tried require once and I dont think is is getting the project_id. The way I am assigning the ID is simply when you click the link the a href has test.php?project_id=fl. using require once i get this error ( ! ) Notice: Undefined index: project_id in C:\wamp\www\workflow_test\callscripts\workflow\epc\workflowvars.php on line 2 Call Stack # Time Memory Function Location 1 0.0011 372768 {main}( ) ..\lostcard.php:0 2 0.0027 376792 require_once( 'C:\wamp\www\workflow_test\callscripts\workflow\epc\workflowvars.php' ) ..\lostcard.php:56
I think the problem is that your using $project_id from within a function called main. So at the top of your main function put global $project_id;.
@OmarJackman sorry for being such a PHP newb but would i add the global part to the external file?
|
1

Personally I would recommend REQUIRE_ONCE instead of Include as it ends up being safer. You may want to check out DEFINE as well so you can use Constants instead of variables.

Comments

1

PHP manual: include

Example: include 'vars.php';

Other possibilities:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.