emtec Posted December 19, 2008 Share Posted December 19, 2008 i'm trying to transfer an array from one page to an other one, in a session array /session: <?php $_SESSION['info'] = array(); array echo: <?php //check if info box needs to be showen if (!empty($_SESSION['info'])){ echo "<div class='info_message'>"; $nr = count($_SESSION['info']); for ($row = 0; $row < $nr; $row++) { echo"<p><img src='images/icons/".$_SESSION['info'][$row]['icon']."' width='16' height='16' /> ".$_SESSION['info'][$row]['text']."</p>"; } //close info box echo "</div><!-- end info_message -->"; unset($_SESSION['info']); } storing array in session on an other page: <?php array_push($_SESSION['info'], array (icon => "add.png",text => ADMINADDINFO )); i just get an empty session, if i copy the array push on the same page, it will work. can any1 tell me what i'm doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/137631-solved-displaying-array-stored-in-a-session-from-external-page/ Share on other sites More sharing options...
.josh Posted December 19, 2008 Share Posted December 19, 2008 need to put session_start(); before you can use session vars (on any page you use them, not just where you assign something to them). It also needs to come before any output, even blank spaces or lines. Quote Link to comment https://forums.phpfreaks.com/topic/137631-solved-displaying-array-stored-in-a-session-from-external-page/#findComment-719368 Share on other sites More sharing options...
emtec Posted December 19, 2008 Author Share Posted December 19, 2008 yeah done that on both pages Quote Link to comment https://forums.phpfreaks.com/topic/137631-solved-displaying-array-stored-in-a-session-from-external-page/#findComment-719369 Share on other sites More sharing options...
.josh Posted December 19, 2008 Share Posted December 19, 2008 did you declare $_SESSION['info'] as an array, before trying to array_push something into it? edit: yes you did. Sorry, kind of hard to tell, when you have your code all broken up and out of order like that. Repost the code together and in order, please. Quote Link to comment https://forums.phpfreaks.com/topic/137631-solved-displaying-array-stored-in-a-session-from-external-page/#findComment-719373 Share on other sites More sharing options...
emtec Posted December 19, 2008 Author Share Posted December 19, 2008 i will post some more info, maby there is something wrong with somthing else index.php <?php session_start(); $_SESSION['info'] = array(); //some other code include('inc/infoboxes.php'); //some other code inc/infoboxes.php <?php //check if info box needs to be showen if (!empty($_SESSION['info'])){ echo "<div class='info_message'>"; $nr = count($_SESSION['info']); for ($row = 0; $row < $nr; $row++) { echo"<p><img src='images/icons/".$_SESSION['info'][$row]['icon']."' width='16' height='16' /> ".$_SESSION['info'][$row]['text']."</p>"; } //close info box echo "</div><!-- end info_message -->"; unset($_SESSION['info']); } ?> external page <?php session_start(); // some other code array_push($_SESSION['info'], array (icon => "add.png",text => ADMINADDINFO )); Quote Link to comment https://forums.phpfreaks.com/topic/137631-solved-displaying-array-stored-in-a-session-from-external-page/#findComment-719374 Share on other sites More sharing options...
.josh Posted December 19, 2008 Share Posted December 19, 2008 You initialize $_SESSION['info'] and then turn around and then include infoboxes.php. You didn't actually assign anything to $_SESSION['info'] before the include. What is that external page? The code in "external page" needs to happen somewhere before the include in your index.php Quote Link to comment https://forums.phpfreaks.com/topic/137631-solved-displaying-array-stored-in-a-session-from-external-page/#findComment-719375 Share on other sites More sharing options...
emtec Posted December 19, 2008 Author Share Posted December 19, 2008 on the extrenale page you get redirected to the index.php after assigning the array Quote Link to comment https://forums.phpfreaks.com/topic/137631-solved-displaying-array-stored-in-a-session-from-external-page/#findComment-719377 Share on other sites More sharing options...
.josh Posted December 19, 2008 Share Posted December 19, 2008 Okay, so let me get this straight: your coding order is this? (look at the comments I added): index.php <?php session_start(); $_SESSION['info'] = array(); //some other code // CALL EXTERNAL PAGE HERE include('inc/infoboxes.php'); //some other code external page <?php session_start(); // some other code array_push($_SESSION['info'], array (icon => "add.png",text => ADMINADDINFO )); // REDIRECT TO INDEX.PHP Quote Link to comment https://forums.phpfreaks.com/topic/137631-solved-displaying-array-stored-in-a-session-from-external-page/#findComment-719378 Share on other sites More sharing options...
emtec Posted December 19, 2008 Author Share Posted December 19, 2008 no the exernal page isnt included in the index.php, its accessed by submitting a form. then that external file adds in the array and then redirects back to index.php Quote Link to comment https://forums.phpfreaks.com/topic/137631-solved-displaying-array-stored-in-a-session-from-external-page/#findComment-719379 Share on other sites More sharing options...
.josh Posted December 19, 2008 Share Posted December 19, 2008 Okay well then it sounds like your index.php is overwriting the array_push with $_SESSION['info'] = array(); Quote Link to comment https://forums.phpfreaks.com/topic/137631-solved-displaying-array-stored-in-a-session-from-external-page/#findComment-719380 Share on other sites More sharing options...
emtec Posted December 19, 2008 Author Share Posted December 19, 2008 hmm ok, is there any way how i can resolve this? Quote Link to comment https://forums.phpfreaks.com/topic/137631-solved-displaying-array-stored-in-a-session-from-external-page/#findComment-719381 Share on other sites More sharing options...
.josh Posted December 19, 2008 Share Posted December 19, 2008 Well, I'm still kind of confused about your program flow... but it sounds like if you put that session var init in your external page, that should do the trick. Quote Link to comment https://forums.phpfreaks.com/topic/137631-solved-displaying-array-stored-in-a-session-from-external-page/#findComment-719382 Share on other sites More sharing options...
emtec Posted December 19, 2008 Author Share Posted December 19, 2008 ok that was the problem thx a lot m8 i solved it this way <?php //declare arrays if (!isset($_SESSION['info'])) { $_SESSION['info'] = array(); } Quote Link to comment https://forums.phpfreaks.com/topic/137631-solved-displaying-array-stored-in-a-session-from-external-page/#findComment-719383 Share on other sites More sharing options...
.josh Posted December 19, 2008 Share Posted December 19, 2008 ah, yeah, guess that would have the same effect. Quote Link to comment https://forums.phpfreaks.com/topic/137631-solved-displaying-array-stored-in-a-session-from-external-page/#findComment-719386 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.