Page 1 of 1

$_SESSION and include()

Posted: Wed Jan 21, 2004 10:24 am
by php_wiz_kid
OK, problem:

I created a user registration form working. I decided to modify it for security reasons. What I did was have one page called profile.php include the appropriate files according to the URL. The problem is that when I include the files I can't send anything from profile.php to the included page. I can't send variables, $_SESSION variables, nothing! So here's my code:

profile.php

Code: Select all

<?php
require($_SERVER['DOCUMENT_ROOT'].'/.../functions.php');
$doc_root = DocRoot('http://www.rockpromo.com');
session_start();
if($_GET['mode'] == 'register') {
	if($_GET['submit'] == 'true') {
		$_SESSION['sub'] = true;
	}
	include($doc_root['local']."/.../register.php");
} else {
	header("Location: ".$doc_root['local']."/index.php");
}
?>
register.php

Code: Select all

<?php
session_start();
echo $_SESSION['sub'];
?>
So in conclusion register.php will not print anything on the page when profile.php?mode=register&submit=true

Posted: Wed Jan 21, 2004 10:30 am
by DuFF
Not sure on this, but it may be because you are setting it to true. Try something like:

Code: Select all

<?php
session_start(); 
if($_SESSION['sub'])
{
echo "It's Set";
}
else
{
echo "It's Not Set";
}
?>

Posted: Wed Jan 21, 2004 10:32 am
by php_wiz_kid
I get is not set with profile.php?mode=register&submit=true

Posted: Wed Jan 21, 2004 2:34 pm
by DuFF
Oh, sorry, last time I didn't have enough time to look over your code. The problem may be that you are including register.php, instead you should just use a header to redirect the user right to it. I know with cookies that you cannot use the cookie values until the script that created them has ended. So just make sure that this script ends and sends the user to the other page.

Posted: Wed Jan 21, 2004 8:14 pm
by php_wiz_kid
Yeah, that's what I figured was happening. I included it so that the URL would stay profile.php, and I wouldn't have to switch around files into different, less sensitive folders. Thanks for the help. I'll come back here tomorrow if I have any more trouble.