Asked  8 Months ago    Answers:  5   Viewed   33 times

So I wonder if it is possible to get a variable from a specific php-file when the variable-name is used in multiple php-file. An example is this:

<header>
 <title>
  <?php echo $var1; ?>
 </title>
</header>

page1.php has $var1 = 'page1' page2.php has $var1 = 'page2'

footer.php should have <a href="">$var1 from page1</a><a href="">$var1 from page2</a>

Ok the example is a bit abstract, but as short as I can make it. I think you get what I am getting at! So it is the in the footer I am after! Got any solutions?

 Answers

17

You can, but the variable in your last include will overwrite the variable in your first one:

myfile.php

$var = 'test';

mysecondfile.php

$var = 'tester';

test.php

include 'myfile.php';
echo $var;

include 'mysecondfile.php';
echo $var;

Output:

test

tester

I suggest using different variable names.

Wednesday, March 31, 2021
 
Corsair
answered 8 Months ago
86

You should point to your vendor/autoload.php at Settings | PHP | PHPUnit when using PHPUnit via Composer.

This blog post has all the details (with pictures) to successfully configure IDE for such scenario: http://confluence.jetbrains.com/display/PhpStorm/PHPUnit+Installation+via+Composer+in+PhpStorm

Related usability ticket: http://youtrack.jetbrains.com/issue/WI-18388

P.S. The WI-18388 ticket is already fixed in v8.0

Wednesday, March 31, 2021
 
ojrac
answered 8 Months ago
95

You need to call session_start(); on both pages.

Wednesday, March 31, 2021
 
csi
answered 8 Months ago
csi
42

Use the header function

<?php
...
$id = $user_profile['id'];
$_SESSION['id'] = $id;
header('Location: checkIfExsists.php?id='.$id);
?>

on the checkIfExsists.php get the variable with

$id = $_GET["id"];

That would solve your problem the way you want it to be solved, but, this isn´t neccesarilly the way it should be solved, maybe inside checkIfExists.php should be a class instead of structured code with a public function to check existance checkExistance, so you will then just need:

include_once(checkIfExists.php);
$check = new checker();
$exists = $check->checkExistance($id) ;

this way you do not have to be jumping between files and you can have a better way to re-use code, regards.

Wednesday, March 31, 2021
 
BradM
answered 8 Months ago
79

On Mac OS X environment variables available in Terminal and for the normal applications can be different, check the related question for the solution how to make them similar.

Note that this solution will not work on Mountain Lion (10.8).

Saturday, May 29, 2021
 
Nate
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share