473,503 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Anyway to pass variables down to an include()

19 New Member
Hey folks,

I was wondering if there is anyway to pass down a variable to an include.

For example I have 2 pages:

-page1.php
-page2.php

page1.php has a bunch of variables. page1.php also has:

include(page2.php);

My question is, can page2.php access any of the variables from page1.php? I tried using Sessions but no success.

your thoughts would be greatly appreciated

Al
Sep 13 '07 #1
3 2423
JeremyMiller
69 New Member
They should already exist.

page1.php
[code=php]
<?php
$my_variable = __file__;
include("page2.php");
?>
[/php]

page2.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo $my_variable;
  3. ?>
  4.  
Sep 13 '07 #2
Weisbartb
36 New Member
Use a global variable

[PHP]
global $rawr;
$rawr = 1;
[/PHP]
When you access $rawr it will display as 1 on any page included after it was declared.

Edit
Just read that you tried to use sessions. You can do that but you need to make sure you do a
[php]
session_start();
[/php]
at the top of the first page.
Sep 13 '07 #3
aalmakto
19 New Member
Thanks guys,
The global variable worked :)

Al
Sep 13 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
31529
by: John | last post by:
I would like to pass array variables between URLs but I don't know how. I know its possible with sessions, but sessions can become useless if cookies are disabled. I have unsuccessfully tried...
12
1772
by: Casey | last post by:
Yeah, I know this question was asked by someone elselike 2 weeks ago. But I need some additional help. I have a program I'm developing, and multiple different forms will be opened. For now though,...
41
8268
by: Berk Birand | last post by:
Hi, I am just learning about the array/pointer duality in C/C++. I couldn't help wondering, is there a way to pass an array by value? It seems like the only way to do is to pass it by...
5
1911
by: DamonChong | last post by:
Hi, I am still struggling to master C++ and is trying to understand how to achieve passing arguments using pointers. I got some questions that I like to post to the experts here, hope you can...
2
12345
by: macyp | last post by:
I have to pass values from one aspx page to another. The controls I have in the first page are: a textbox, 3 drop down lists, and 2 check boxes, and a submit button. It is a search page, and the...
9
2175
by: One | last post by:
I have a main.php file that calls a php navigation menu. I want to pass the menu file a parameter to tell it which menu to display. Inside the main.php I have : include...
28
4671
by: Bill | last post by:
Hello All, I am trying to pass a struct to a function. How would that best be accomplished? Thanks, Bill
14
2146
by: Matt | last post by:
Hello. I'm after some general advice. At the moment i have some code that should run a FOR loop a set number of times. Each time the structure stamps is read in as follows: for( i = 0 ; i <...
6
2698
by: lisp9000 | last post by:
I've read that C allows two ways to pass information between functions: o Pass by Value o Pass by Reference I was talking to some C programmers and they told me there is no such thing as...
0
7072
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.