Forum Topic: Staying Var

(98 views • 8 replies)

This topic is 1 page long.

<< < > >>
None

Loccie

Reply To Post Reply & Quote

Posted at: 7/17/06 08:14 PM

Loccie NEUTRAL LEVEL 16

Sign-Up: 02/27/04

Posts: 1,026

Hi again, What I need to know how is how to send a variable to another page (this I know how to do) and once that variable is on that page is stays on it. So on page one I send a var to page 2 which is included in page 1. This works the script knows what the var is. But this page is included on other page to so I want it to stay recognized there this does not work. I tried this with sessions also I tried sending the var to page 2 with $_POST but when I clicked on another page it was no longer recognized again. So how do I make it that page 2 keeps recognizing the var once page 2 recieved the var once? Of course if you close the browser it may stop recognizing the var.

Thanks, Loc


None

WoogieNoogie

Reply To Post Reply & Quote

Posted at: 7/17/06 08:26 PM

WoogieNoogie LIGHT LEVEL 14

Sign-Up: 06/26/05

Posts: 3,195

Use sessions ;)

Just set the variable...

$var = "data";

Then start the session...

session_start()

Then put the variable in the session.

$_SESSION['variable'] = $var;

Now, every page that you call on that you want the variable, start the session (don't forget to start it again, very important)...

session_start()

Then set the variable from the session.

$var = $_SESSION['variable']

Hope that helped :)


None

Loccie

Reply To Post Reply & Quote

Posted at: 7/18/06 05:45 AM

Loccie NEUTRAL LEVEL 16

Sign-Up: 02/27/04

Posts: 1,026

thanks but I don't think this is what I need. What I do is set a variable on page 1 that is then send to page 2. Page 2 is a page that is included in all the pages (also on page 1). On page 2 there is a code that looks a bid like this:

if ($thatvarr == 1) {
echo 'ok';
} else {
echo 'not ok';
}

now on page 1 where this var is actually set page 2 shows 'ok' but on other page is shows 'not ok'. So I want it to be that when the var is set on page one and send to page 2 it stays on page 2. Even if you go to another page where it is included. I hope you understand me better now.


None

henke37

Reply To Post Reply & Quote

Posted at: 7/18/06 07:57 AM

henke37 NEUTRAL LEVEL 16

Sign-Up: 09/10/04

Posts: 2,627

Sounds like another case of the http path inclusion.
Do not use http:// in a require statement!
It will not execute the file, it will execute the output of the page since it will make another http request. That means that any variables on the caller side wont get transfered to the included file!
The solution:

Stop using http:// and use either a relative path like 'file.php' or an absolute path like '/var/www/may/changedepending/on/your/host
/file.php'.

Btw, the relative paths is allways relative to the first script that calls an include. Use "require dirname(_FILE_).'/file.php'" if you want it to be relative to the file that is incudeing.

Move on to ActionScript 3! And please, drop the mysql PHP extension, it's so stale that it lacks features that is no longer considered new! Go mysqli or pdo instead.


None

Loccie

Reply To Post Reply & Quote

Posted at: 7/18/06 02:06 PM

Loccie NEUTRAL LEVEL 16

Sign-Up: 02/27/04

Posts: 1,026

At 7/18/06 07:57 AM, henke37 wrote: Sounds like another case of the http path inclusion.
Do not use http:// in a require statement!
It will not execute the file, it will execute the output of the page since it will make another http request. That means that any variables on the caller side wont get transfered to the included file!
The solution:

Stop using http:// and use either a relative path like 'file.php' or an absolute path like '/var/www/may/changedepending/on/your/host
/file.php'.

Btw, the relative paths is allways relative to the first script that calls an include. Use "require dirname(_FILE_).'/file.php'" if you want it to be relative to the file that is incudeing.

thanks, this works but not if I link from another folder. e.g. :

/folder1/folder2/folder3/Page1.php

needs to have a require to page 2 which is in folder:

/login/Page2.php

How can I get it to require something in a case like this?


None

Loccie

Reply To Post Reply & Quote

Posted at: 7/18/06 07:49 PM

Loccie NEUTRAL LEVEL 16

Sign-Up: 02/27/04

Posts: 1,026

I searched some more on google and I found this

<?php include_once FP_FILE_ROOT.'/path/to/file';?>

and

require ($_SERVER["DOCUMENT_ROOT"]."/path/to/file.
php");

None of these worked. Is it beacause they are for higher versions then php 4.4.2 or is it because I did something wrong with the path? (If you want to know what I want check my previous reply.)


None

WoogieNoogie

Reply To Post Reply & Quote

Posted at: 7/18/06 07:58 PM

WoogieNoogie LIGHT LEVEL 14

Sign-Up: 06/26/05

Posts: 3,195

Maybe try this...

include("../login/Page2.php");

The ../ goes up one level.


None

Loccie

Reply To Post Reply & Quote

Posted at: 7/18/06 08:07 PM

Loccie NEUTRAL LEVEL 16

Sign-Up: 02/27/04

Posts: 1,026

At 7/18/06 07:58 PM, WoogieNoogie wrote: Maybe try this...

include("../login/Page2.php");

The ../ goes up one level.

Well thanks but it does not work I linked to page 2 that is in /folder1/page2.php from a file in the root directory (where the map login is in) with this code:

include(".. /folder1/page2.php");

but it does not work. Also if I want to do that thingy I explained in a previous post (different directory) this wont work right?


All times are Eastern Standard Time (GMT -5) | Current Time: 08:34 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!