Asked  2 Years ago    Answers:  5   Viewed   100 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

3

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.

Friday, August 12, 2022
1

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

Sunday, July 31, 2022
 
3

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

Wednesday, December 28, 2022
 
5

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.

Monday, November 14, 2022
 
4

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).

Sunday, November 6, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 

Browse Other Code Languages