0

hi i got a variable assigned time as its value in a script called a.php

a.php

<?php

$orgtimestamp = date("h:i:sa");

?>

i want this

$orgtimestamp

to be called by another script and assigned its time to another variable in the new script.

i tried it as follows with no luck for sometime, following is my script.

<?php
$A = new a();
$time = $A->orgtimestamp
?>
1
  • 1
    I suggest you read up on the basics of PHP first because this makes no sense. Yes, we are here to help, but if you don't even have the basics, we can't help you with anything. Commented Sep 10, 2014 at 8:57

4 Answers 4

2
<?php

include('a.php');

$time = $orgtimestamp;

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

Comments

0

@mariobgr answer is good Also you can use session. using session you can get variable

session_start();
$orgtimestamp = date("h:i:sa");
$_SESSION['orgtimestamp'] = $orgtimestamp;

get session var value on second page

session_start();
$time = $_SESSION['orgtimestamp'];

Comments

0

Including the first script in the second should do the trick. Is $orgtimestamp defined in a class or function of a.php ? This is a fairly easy task. Is it somehow more complicated than you posted?

Comments

0

You are trying to access a as a class , so you need to define a class in a.php like :

 class a
    {
     public $orgtimestamp;
     function __construct()
     {
       $this->orgtimestamp = date("h:i:sa");
     }
    }

Now include this file in your another file

<?php
include('a.php');
$A = new a();
$time = $A->orgtimestamp;

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.