0

Dear All,
I have two .php page. In my main php I call the other via the require_once method. Then in the main .php I declare and assigne variable and I tried to read the value in the require_once php I am not able to see the value. How can I achieve this ? Thank you.

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by jigarvyas
0

You should be able to use a variable from the main program unless you are using Functions and the variable was defined in / being used in a Function without being defined as Global. If that is not it, then you need to post some code.

0

Dear Chris,
Is there any difference between require and require_once?

0

Pasting from http://www.geekinterview.com/question_details/22645

"Difference between require() and require_once(): require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page).
So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error."

What you said you have tried should work without a problem
main.php

<?php
$test = "Hello";
?>

test.php

<?php
require_once "main.php";
echo $test;
?>

As Chris said, pls paste some code that you have used in case you are still facing problems

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.