freaklikeme Posted November 7, 2010 Share Posted November 7, 2010 Hello, I have been studying PHP for less than a year so please be gentle. I am building an agency website where users can add themselves etc. What I want to do now is allow clients to collect a list of these users which they can submit to the site along with a job description. What I actually need help with is sending the usernames to a 'collection' page. I want to allow the client to move between the profile pages selecting the users they like the look of and then be able to go to the 'cart/collection' page and see their list. I have a basic knowledge of sessions just no real idea how to pass variables/arrays. Any help would be much appreciated. Cheers - Lee. Link to comment https://forums.phpfreaks.com/topic/218024-a-kick-in-the-right-direction-session-vars/ Share on other sites More sharing options...
.josh Posted November 10, 2010 Share Posted November 10, 2010 page1.php <?php session_start(); $_SESSION['someVar'] = 'this is a session variable'; $_SESSION['someArray'][] = 'this is a session array (element 0)'; $_SESSION['someArray'][] = 'this is a session array (element 1)'; $_SESSION['someArray'][] = 'this is a session array (element 2)'; echo "<a href = 'page2.php'>click to go to page 2</a>"; ?> page2.php <?php session_start(); echo $_SESSION['someVar'] . "<br/>"; foreach ($_SESSION['someArray'] as $value) { echo $value . "<br/>"; } In most cases, there are basically there are 2 things to note: 1) In order to make use of session variables (or arrays), you have to have session_start() on your page somewhere before actually using the var/array, and it also has to be put BEFORE any output (including any whitespace). 2) All session variables and arrays are contained within the $_SESSION super global array. So session variables/arrays are really just elements of the $_SESSION array. You can see it better by doing on page2.php <?php session_start(); echo "<pre>"; print_r($_SESSION); echo "</pre>"; ?> Link to comment https://forums.phpfreaks.com/topic/218024-a-kick-in-the-right-direction-session-vars/#findComment-1132736 Share on other sites More sharing options...
ManiacDan Posted November 10, 2010 Share Posted November 10, 2010 3) Sessions are tied to a specific browser session. Closing the browser, clearing its cookies, or switching to another computer will destroy the session. -Dan Link to comment https://forums.phpfreaks.com/topic/218024-a-kick-in-the-right-direction-session-vars/#findComment-1132744 Share on other sites More sharing options...
freaklikeme Posted November 10, 2010 Author Share Posted November 10, 2010 Firstly thank you so much Crayon Violent & ManiacDan for taking the time to answer. From what you said I have about 1000 more questions... I'll try to reign them into a couple. 1. I presume (know) the log in script I am using starts a session - can you start 2 sessions? For the other 999 questions I think it's better I show you what I already have and point out where it fails. I start with this (only on the home page): session_start(); $_SESSION['wishlist'] = $_POST['wishlist']; on all pages. $wishlist = $_SESSION['wishlist']; echo $wishlist; The problem with above is... the variable $wishlist passes to all the other pages but does not pass back to the home page - also you can not post to the other pages, also it is a single variable and I need it as an array. I have an agency site, when you log in as a client you are given an extra option (a form) which posts the username (of the current page) dancer to it's SELF - what I am trying to do is collect all the names as an array and display them on a page where the client can then submit it to the casting team. Crayon Violent if you could expand on your array example, explaining how to create an array from a set of post results. PS. If you want to see what I already have (maybe it will make more sense than my ramblings) go to pirouette-dance-agency.co.uk the submit buttons under 'news' is what I have so far. Lee. Link to comment https://forums.phpfreaks.com/topic/218024-a-kick-in-the-right-direction-session-vars/#findComment-1132797 Share on other sites More sharing options...
simshaun Posted November 10, 2010 Share Posted November 10, 2010 You can utilize more than one session on a single request, but not at the same time. Check out http://stackoverflow.com/questions/609756/can-you-switch-php-sessions-in-a-session. Crayon or Dan can answer the rest. Link to comment https://forums.phpfreaks.com/topic/218024-a-kick-in-the-right-direction-session-vars/#findComment-1132819 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.