We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,089 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Using php variables

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.

6
Contributors
5
Replies
2 Days
Discussion Span
9 Months Ago
Last Updated
6
Views
DaveyMoyes
Junior Poster
122 posts since May 2009
Reputation Points: 9
Solved Threads: 0
Skill Endorsements: 0

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

jkon
Posting Whiz
383 posts since Jan 2009
Reputation Points: 124
Solved Threads: 63
Skill Endorsements: 4

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[];

?>
godzab
Junior Poster in Training
65 posts since Jun 2012
Reputation Points: 0
Solved Threads: 5
Skill Endorsements: 0

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

jardrake
Newbie Poster
2 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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 = '';}
esma.ramirez
Newbie Poster
7 posts since Aug 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 0

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.

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0686 seconds using 2.71MB