Hi all, I'm working on a new project but I'm stuck. I'm stuck with passing variables. Example: file1.php : <?php $id ="abc123"; ?> PHP: file2.php : <?php echo $id; ?> PHP: I want to make this happen . What is the right piece of code for it? (I don't want to 'include' the whole file) Thanks, Akos
file1.php sends the id number like this file2.php?id=$id file2.php <?php $id = $_GET['id']; echo $id; ?> Code (markup):
Please take a look at the php session information. It is meant to pass the vars to different php files. http://www.php.net/manual/en/function.session-start.php <?php // page1.php session_start(); echo 'Welcome to page #1'; $_SESSION['favcolor'] = 'green'; $_SESSION['animal'] = 'cat'; $_SESSION['time'] = time(); // Works if session cookie was accepted echo '<br /><a href="page2.php">page 2</a>'; // Or maybe pass along the session id, if needed echo '<br /><a href="page2.php?' . SID . '">page 2</a>'; ?> PHP: <?php // page2.php session_start(); echo 'Welcome to page #2<br />'; echo $_SESSION['favcolor']; // green echo $_SESSION['animal']; // cat echo date('Y m d H:i:s', $_SESSION['time']); // You may want to use SID here, like we did in page1.php echo '<br /><a href="page1.php">page 1</a>'; ?> PHP: If you don't want to have to session_start each time and this is only for your personal server then you could use the php.ini to auto start the session for each user connection. See below for the var needed to be set to true, 1 in the php.ini file. session.auto_start boolean - session.auto_start specifies whether the session module starts a session automatically on request startup. Defaults to 0 (disabled).