views:

69

answers:

4

There is a $variable, its value is a big Array().

It is created inside the function one() { ... } on the first.php page.

first.php has form with method="post", after submition page reloads on second.php

Is there any way to get value of $variable inside function two() { ... } on the second.php?

Seems I can post value of $variable within form, the problem is it can contain more than thousand symbols.

Thanks.

+4  A: 

You are looking for Sessions. Sessions allow the script to store user-specific data on server side without having to pass it through a form.

There is a full reference in the Sessions book in the PHP manual.

There's a complete simple example on the session_start() manual page.

Pekka
can you give some code? first hear about sessions
Happy
@Ignatz see the second link, it has a full working example.
Pekka
@Ignatz then chances are you don't need session_start() at all: Just save your data into `$_SESSION`. To make sure you don't interfere with anything set by Wordpress, best prefix your variables with something unique, e.g. `$_SESSION["Ignatz_variablename"]` (you know what I mean) In future questions, make sure you *always* mention that you're in a Wordpress project, it's almost always important.
Pekka
You can only start sessions once. Wrap your `session_start()` in `if('' === session_id()){ session_start() }`.
Treffynnon
+2  A: 

You can use sessions.

Simple example of usage is here: http://www.w3schools.com/php/php_sessions.asp

MartyIX
+3  A: 

Use "session_start()" function at the very beginning of any PHP web page, just after the first PHP start tag (<?php).

Then store the variable of yours into a superglobal session array variable, in the "first.php" page like:-

<?php
session_start(); // This line must be at the very beginning of this PHP page.

function one() {
    // blah, blah, ...

    if(isset($variable) && !empty($variable)) {
        $_SESSION['customVariable'] = $variable;
    }

    // some more blah, blah, ...
}
?>

Now if you come to the "second.php" page, you need to access this page's function as:-

<?php
function two() {
    // if any blah, blah, ...

    if(isset($_SESSION['customVariable']) && !empty($_SESSION['customVariable'])) {
        $variable = $_SESSION['customVariable'];
    }

    // next series of blah, blah, ...
}
?>

But in this "second.php" page, the "session_start()" function must be written at the very beginning of this page just after the first PHP start tag.

Hope it helps.

Knowledge Craving
A: 

You can see some examples at php tutorial