0

My file layout is as follows:
Index.php: (URL = domain/index.php)

<?php
	session_start();
?>
<!-- BUNCH OF HTML -->
<?php
	if($_GET['page'] == 'portfolio')
		include('pages/portfolio.php');
?>
<!-- BUNCH OF HTML -->

Portfolio.php: (URL = domain/index.php?page=portfolio)

session_start();
if($_GET['view'] == 0){ // URL would be domain/index.php?page=portfolio&view=0
	$_SESSION['catImages'] = array();
	$_SESSION['catImages'][0] = "TEST";
} else { // URL would be domain/index.php?page=portfolio&view=#
	echo $_SESSION['catImages'][0];
}

In my script, I am including portfolio.php into index.php. When user is on domain/.../?view=0 .. it should create a new session array variable and set its first element to TEST. When the user is on any other page, domain/.../?view=# .. it should output the value.

For some reason, it acts like the session variable was not created.

My current output: (domain/index.php?page=portfolio&view=#)

ERROR: NULL VARIABLE

My expected output: (domain/index.php?page=portfolio&view=#)

TEST

And yes, obviously the user first goes to view=0 by default and then clicks on an item which takes him/her to view=# ... so it should create session variable at view=0 and carry it on to view=# but it doesn't do that.

Thank you for all the help in advance.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Shanti C
0

Okay on your index file you have used:


<?php
if($_GET == 'portfolio')
include('pages/portfolio.php');
?>

That should be:


<?php
if($_GET == 'portfolio'){
include('pages/portfolio.php');
}
?>

That might be the only problem :)
If you have headers already sent issues remove your session_start from portfolio and it should be fine ;)

0

For some reason, it acts like the session variable was not created.

My current output: (domain/index.php?page=portfolio&view=#)
Quote ...

ERROR: NULL VARIABLE

My expected output: (domain/index.php?page=portfolio&view=#)
Quote ...

TEST

First test your session is created or not..
like this:

session_start();
if($_GET['view'] == 0){ // URL would be domain/index.php?page=portfolio&view=0
	$_SESSION['catImages'] = array();
	$_SESSION['catImages'][0] = "TEST";
} else { // URL would be domain/index.php?page=portfolio&view=#
if(isset($_SESSION['catImages']) && !empty($_SESSION['catImages']))	
echo "Session not created";
else
echo $_SESSION['catImages'][0];
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.