I have an array in one php1
file which I want to access in another php2
file but if i use either include or require once am also getting the output of the php1
file. I want to access only the variables from php1
but not the output. Can anyone suggest how to do that. In php1
I have lot of menus and boxes which I don't want to include in php2
except the variables.
<?
session_start();
require_once('home.php');
if($_GET["reset"]==1)
{
session_destroy();
header('Location: index.php');
}
?>
if i use this am getting all the output from the home.php
page. I want only the variables.
将主页上的变量转换为可以通过函数或更好的方式访问的变量,使其成为会话变量
is there some way without using function or session to access the variables
As per your request. A simple skeleton to show you how it is done.
We pass the variable $myVar
through the URL and use $_GET
in the next page to use it. We use htmlspecialchars();
to clean user input.
We use the if (isset($_GET['myVar']))
so it doesn't throw Notice: Undefined index error .
pageOne.php
<?php
$myVar = "My variable one.";
echo "<a href='pageTwo.php?myVar=" . $myVar . "'>Page Two</a>"
?>
pageTwo.php
<?php
if (isset($_GET['myVar'])) {
$myVar = htmlspecialchars($_GET['myVar'], ENT_QUOTES);
// Now you can use $myVar.
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.