Forum Moderators: coopster
In the following example, I have a main.php that calls an include file. Basically, the main.php contains html code before the include is called. I need the variable created in the main.php to be carried across other pages. Hence, I begin the session in the include.php and the session continues in the view.php.
What happens is, due to the HTML code above the PHP, the session variable does not get carried across to the other pages.
Is there any possible way to carry the $test variable across the other pages through sessions and not through POST? The file main.php cannot be modified. Include.php and view.php can be modified.
-- Contents of main.php --
This section above the PHP contains HTML code
<?php
// This file cannot be modified
$test = "This is a Test";
include('include.php');
?>
-- Contents of include.php --
<?php
// This file can be modified
session_start();
$_SESSION['test'] = $test;
echo "<p><a href='view.php'>Click to View,$_SESSION[test]</a></p>";
?>
-- Contents of view.php --
<?php
session_start();
echo $_SESSION['test'];
?>
I am able to view the $test output in the include.php file. The issue is that the variable does not get carried into view.php
Is there a reason why this is happening? If I remove the HTML code in the main.php file, the variable does get registered and displays correctly in view.php. However, I do not want to remove the HTML in the main.php
-- Contents of include.php --
<?php
// This file can be modified
session_start();
$_SESSION['test'] = $test;
echo "<br>$test<br>";
echo "<p><a href='view.php'>Click to View, $test</a></p>";
?>
-- end --
TIA
[edited by: HoboTraveler at 4:36 am (utc) on Aug. 22, 2006]
Starting a sesson in main.php and modifying main.php is not an option. I am thinking of passing the variable through GET since the session does not work.
Is it possible to hide the variable in GET?
example:
view.php?category=php
However, the user sees the link as view.php without the variable..
view.php
If I remove the HTML code in the main.php file, the variable does get registered
as soon as the first Byte is output to the browser (i.e. your HTML-Stuff), some header stuff is sent - and that seems to be colliding with your session.
IF you can't start the session IN the main file, maybe you could do it BEFORE and calling the main file later? Just guessing.
I'm sure it's possible to handle somehow - and wouldn't resort to adding funny parameters. No, you can't hide them - at least without using mod.rewrite and this way adding unneeded complexity.
Thing is, I do not want the URL containing the variables to be bookmarked.
Basicaly, view.php?category=php should work only when using the link through main.php. Hence, I need the?category=php to be hidden.. How do I implement this with mod-rewrite?
TIA