greenheart Posted October 14, 2009 Share Posted October 14, 2009 Hello I have an array of data in one script on my html/php page. I want to call up this array of data in another php script later down the page, is this possible? The reason for this is because I have the content on my page in tabs, and each tab has a separate php script in it and you can't have one long php script it has to be a single one for each tab. The tabs are AJAX so that they all load in the background at once. The tab thing isn't that important to mention I thought I would justify why I want an answer to this question... Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/177719-arrays-between-php-scripts/ Share on other sites More sharing options...
ialsoagree Posted October 14, 2009 Share Posted October 14, 2009 Just so you're clear, AJAX doesn't load things "all at once." AJAX uses HTTP and loads things on demand. AJAX is stateless, like all HTTP requests. If you have an array and you want to get access to it again, the simplest way would be to save it in a session variable if you're using sessions. You could save it into a cookie but it would be very easy for the user to manipulate. You could save it into a database, but since you need a way to identify the user this wouldn't be much better than just using a session. Quote Link to comment https://forums.phpfreaks.com/topic/177719-arrays-between-php-scripts/#findComment-937074 Share on other sites More sharing options...
greenheart Posted October 15, 2009 Author Share Posted October 15, 2009 Thanks for the reply, how would I use session variables to achieve this? The data is the same for every user (for the time being) so I could save it into a database also you say? I'm also trying to figure out caching too, if that can be done in a database maybe I should go the database route? Thanks for much. Quote Link to comment https://forums.phpfreaks.com/topic/177719-arrays-between-php-scripts/#findComment-937132 Share on other sites More sharing options...
RussellReal Posted October 15, 2009 Share Posted October 15, 2009 not too sure a session will work with AJAX but I guess it could but I never used a session with an ajax request so I wouldn't know but alot of problems on here have to do with AJAX and session problems.. so if I were you I'd go with the database idea Quote Link to comment https://forums.phpfreaks.com/topic/177719-arrays-between-php-scripts/#findComment-937142 Share on other sites More sharing options...
mrMarcus Posted October 15, 2009 Share Posted October 15, 2009 no need for database or sessions .. just attach a variable to the URL, ie. ajax_page.php?foo=bar .. and retrieve it within the AJAX script as $_GET['foo'], where 'foo' is one of your variable names. Quote Link to comment https://forums.phpfreaks.com/topic/177719-arrays-between-php-scripts/#findComment-937178 Share on other sites More sharing options...
ialsoagree Posted October 16, 2009 Share Posted October 16, 2009 not too sure a session will work with AJAX but I guess it could but I never used a session with an ajax request so I wouldn't know but alot of problems on here have to do with AJAX and session problems.. so if I were you I'd go with the database idea I don't have any problems with AJAX and sessions. AJAX sends the exact same HTTP request as a regular webpage load including cookies etc. so using start_session() gets you access to the user's session just as it would a regular HTTP request. Quote Link to comment https://forums.phpfreaks.com/topic/177719-arrays-between-php-scripts/#findComment-938144 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.