How do i add variables from

$var1=urlencode(''.$var1.''); 

on page one.php
and use the values from the above variables on page two.php

$var1 = $criteria['".$var1."'];
if($var1=='') $var1 = '';

Page two is included in page one and I am trying to use the same variable value.

You want to cash those variable with visit scope (if I got your question right) …so why don’t you use session ?

As jkon said, just use a cookie or a session. So lets say this is page1.php:

<?php 

    $var1 = 55;
    setcookie('var1', $var1, time() * 60*60*24*7); //this cookie will expire in one week

?>

then in page2.php, if you want to access $var1 then:

<?php 

    $varFromAnotherPage = $_COOKIE['var1']; //now we will retrive the cookie and its value by using $_COOKIE[];

?>
Member Avatar for jardrake

Two Options
1: Pass it from one page to another using sessions or post data
2: Use an include or require.

PHP Include and Require Tutorial

Using php variables

How do i add variables from

on page one.php
and use the values from the above variables on page two.php

$var1 = $criteria['".$var1."'];
if($var1=='') $var1 = '';
Page two is included in page one and I am trying to use the same variable value.

Quoted Text Here

Don't use cookies are a slow thing.. you can do better this:
page1.php

$var1=urlencode($var1); 
$var2=urlencode($var2);

page2.php

include('page1.php');
if($var1==''){$var1 = '';}
if($var2==''){$var2 = '';}

If page two is included in page one you can use variables from page one in page two straight away. If they are different variables they should have different names.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.