Jump to content

Global variable


Karthickraj.s

Recommended Posts

Hi Friends,

      I am new to PHP.I am having some small clarification whether we use a Global variable for accessing one variable value into another PHP file.

 

Example :

 

I will assign the Global variable value in index.php file. I want to get the stored value into index1.php.

 

Is this possible to get the value in PHP?...

 

 

Thanks in advance

Karthick

Link to comment
https://forums.phpfreaks.com/topic/191602-global-variable/
Share on other sites

Thanks for your reply.

 

 

Those pages are separate

 

I get the values using OOPs concepts.

 

That means one common class file that having SET and GET function for the variable.

 

in INDEX file i set the value of the variable

in INDEX1 file i get the STORED value of the variable.

 

with out using SESSION

 

Is this Possible to make in PHP?.

Link to comment
https://forums.phpfreaks.com/topic/191602-global-variable/#findComment-1009995
Share on other sites

Web servers are stateless. All resources created on any page request are destroyed when the request for that page has been serviced. The only connection between any two http requests is what the browser supplies. Sessions work by passing a unique session id between pages by the browser which is matched up with the corresponding session data file on the server.

 

You can create an instance of a class in a session variable by causing the class definition to exist before the session_start() statement.

 

<?php
require 'your_class.php';
session_start();
if(!isset($_SESSION['some_object_name'])){
// create instance
$_SESSION['some_object_name'] = new your_class();
echo 'object created<br />';
} else {
echo 'object exists<br />';
}

$_SESSION['some_object_name']->class_function();
echo $_SESSION['some_object_name']->class_variable;
?>

Link to comment
https://forums.phpfreaks.com/topic/191602-global-variable/#findComment-1010004
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.