| Author |
Message |
gregwun
Beginner


Joined: Aug 04, 2003 Posts: 5
|
Posted: Mon Aug 04, 2003 6:26 pm Post subject: invalid arguments for the "foreach()" method in se |
|
|
I get an error and want to replace the code on my gallery sessions.php page on/around the line that registers the complaint with
$_HTTP_SESSION_VARS ==> $_SESSION
Here is the error: Warning: Invalid argument supplied for foreach() in /home/sites/site32/web/nuking/html/modules/gallery/session.php on line 55
Here is the code I see in the sessions.php page:
53 /* emulate register_globals for sessions */
54 if (!$gallery->register_globals) {
55 foreach($HTTP_SESSION_VARS as $key => $value) {
56 eval("\$$key = & \$HTTP_SESSION_VARS[\"$key\"];");
57 }
58 }
59
60 /*
Could you give me a bit more detail on how to replace the code? Actually, could you post the code so I can just copy it?
thanks
Cobalt RaQ4
PHP 4.06
Gallery URL : http://www.lowpressurehawaii.com/nuking ... s/gallery/
Gallery version: 1.3.4.
Apache version: Apache/1.3.20 Sun Cobalt (Unix) mod_jk/1.1.0 mod_ssl/2.8.4 OpenSSL/0.9.6b PHP/4.0.6 mod_auth_pam_external/0.1 FrontPage/4.0.4.3 mod_perl/1.25
PHP version (don't just say PHP 4, please):
Graphics Toolkit: Netpbm
Operating system: Mac
Web browser/version (if applicable): IE 5.0 |
|
| Back to top |
|
|
AdBot
|
| Post subject: invalid arguments for the "foreach()" method in se |
|
|
|
|
|
| Back to top |
|
 |
fluentdesigns
User


Joined: Jul 31, 2003 Posts: 38
|
Posted: Mon Aug 04, 2003 6:45 pm Post subject: Re: invalid arguments for the "foreach()" method i |
|
|
| im getting the exact error |
|
| Back to top |
|
|
dari
Site Admin


Joined: Mar 03, 2003 Posts: 6287 Location: Washington Township, NJ, USA
|
Posted: Mon Aug 04, 2003 7:34 pm Post subject: |
|
|
please search the forums, this has been answered numerous times before.
on lines 55 and 56, replace $HTTP_SESSION_VARS with $_SESSION
that will solve the problem. |
|
| Back to top |
|
|
gregwun
Beginner


Joined: Aug 04, 2003 Posts: 5
|
Posted: Tue Aug 05, 2003 1:45 am Post subject: |
|
|
Thanks for your help.
But I still get the error.
Maybe I need a bit of background. It's confusing to me that there is a Improved Random script and a Random Script. I have phpnuke 6.0 and Gallery 1.3.4 so can I use the Improved script?
If I can use the Improved Random script, does changing the $HTTP_SESSION_VARS TO $_SESSION rid me of the "Warning: Invalid argument supplied for foreach() in /home/sites/site32/web/" error? Do I have to restart my browser or my computer or what?
While using the older unimproved Random Block that that I downloaded from this site. I replaced the $HTTP_SESSION_VARS to $_SESSION (The one that has two files named block_random.php) and got a parse error exactly like this: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/sites/site32/web/nuking/html/modules/gallery/session.php on line 56.
I got the session.php code below from the help file on your site.
/* emulate register_globals for sessions */
if (!$gallery->register_globals) {
foreach($_SESSION as $key => $value) {
eval("$$key = & $_SESSION["$key"];");
}
}
It doesn't look like the code that I would Have if I replaced $HTTP_SESSION_VARS with $_SESSION like instructed above....What is up? You see there are a bunch of extra \\ s in there...
/* emulate register_globals for sessions */
if (!$gallery->register_globals) {
foreach($_SESSION as $key => $value) {
eval("\$$key = & \$_SESSION[\"$key\"];");
}
}
However both don't work... any help would be appreciated. Meanwhile I'll be searching the forum for clues. |
|
| Back to top |
|
|
dari
Site Admin


Joined: Mar 03, 2003 Posts: 6287 Location: Washington Township, NJ, USA
|
Posted: Tue Aug 05, 2003 7:30 am Post subject: |
|
|
this is the chunk of code you want:
Code: ›
/* emulate register_globals for sessions */
if (!$gallery->register_globals) {
foreach($_SESSION as $key => $value) {
eval("\$$key = & \$_SESSION[\"$key\"];");
}
}
copy that EXACT chunk of code and replace the corresponding line in your session.php file.
the two random block files are totally different. the original just does a random photo. period. if all you want is a random photo each time your users view the page you can grab this one.
the improved random block also does a photo of the hour and photo of the day. READ the articles associated with each block file for the information on what they do. |
|
| Back to top |
|
|
gregwun
Beginner


Joined: Aug 04, 2003 Posts: 5
|
Posted: Tue Aug 05, 2003 4:24 pm Post subject: Re: invalid arguments for the "foreach()" method i |
|
|
I've got the Improved Random Gallery with an edited sessions.php page uploaded into the gallery directory. I still get the invalid arguments for the "foreach()" method in ...line 55. The block seems to be working except for the warning.
Is there something I'm missing? Do I have to delete my cookies, exit the browser, or delete and reload the block?
Here is my sessions.php code :
Code: ›
<?php
/*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2003 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
?>
<?php
// Hack prevention.
if (!empty($HTTP_GET_VARS["GALLERY_BASEDIR"]) ||
!empty($HTTP_POST_VARS["GALLERY_BASEDIR"]) ||
!empty($HTTP_COOKIE_VARS["GALLERY_BASEDIR"])) {
print "Security violation\n";
exit;
}
?>
<?php
/*
* PHP 4.0.1pl2 introduces a bug where you can't unserialize a
* stdClass instance correctly. So create a dummy class to hold all
* of our session data.
*/
class GallerySession {}
if (session_id()) {
/*
* The session is being created externally. This means that if
* we store our data in a GallerySession class, we won't be able
* to deserialize it (because it's not being defined before the
* external session starts). So, we'll have to fall back on using
* stdClass() which will cause problems on older PHP4 servers.
* oh well.
*/
$useStdClass = 1;
}
/* Start a new session, or resume our current one */
session_start();
/* emulate register_globals for sessions */
if (!$gallery->register_globals) {
foreach($_SESSION as $key => $value) {
eval("\$$key = & \$_SESSION[\"$key\"];");
}
}
/*
* Are we resuming an existing session? Determine this by checking
* to see if the session container variable is already set. If not, then
* create the appropriate container for it.
*/
$sessionVar = $gallery->app->sessionVar . "_" . md5($gallery->app->userDir);
session_register($sessionVar);
if (isset($$sessionVar)) {
/* Get a simple reference to the session container (for convenience) */
$gallery->session =& $$sessionVar;
/* Make sure our session is current. If not, nuke it and restart. */
/* Disabled this code -- it has too many repercussions */
if (false) {
if (strcmp($gallery->session->version, $gallery->version)) {
session_destroy();
header("Location: index.php");
exit;
}
}
} else {
/* Register the session variable */
session_register($sessionVar);
/* Create a new session container */
if ($useStdClass) {
$$sessionVar = new stdClass();
} else {
$$sessionVar = new GallerySession();
}
/* Get a simple reference to the session container (for convenience) */
$gallery->session =& $$sessionVar;
/* Tag this session with the gallery version */
$gallery->session->version = $gallery->version;
}
update_session_var("albumName");
update_session_var("version");
update_session_var("albumListPage");
update_session_var("fullOnly");
update_session_var("username", 1);
update_session_var("offline");
update_session_var("offlineAlbums");
if (!isset($gallery->session->offlineAlbums) || $gallery->session->offlineAlbums == null)
{
$gallery->session->offlineAlbums=array();
}
/*
* Process changes to session variables via parameters submitted in a
* POST or GET.
*/
function update_session_var($name, $protected=0) {
global $gallery;
// If this is a protected session variable, don't allow it
// to be changed by data from POST or GET requests.
if ($protected) {
return;
}
$setname = "set_$name";
if (!emptyFormVar($setname)) {
$gallery->session->{$name} = formVar($setname);
}
}
?>
Maybe it just doesn't work with my version of php which I think is 4.0.6.
Any suggestions? Thanks. |
|
| Back to top |
|
|
dari
Site Admin


Joined: Mar 03, 2003 Posts: 6287 Location: Washington Township, NJ, USA
|
Posted: Tue Aug 05, 2003 7:33 pm Post subject: Re: invalid arguments for the "foreach()" method i |
|
|
yes, your PHP is 4.0.6.
your session.php looks fine. i would get a fresh install and overwrite your gallery files. |
|
| Back to top |
|
|
gregwun
Beginner


Joined: Aug 04, 2003 Posts: 5
|
Posted: Thu Aug 07, 2003 6:50 pm Post subject: Re: invalid arguments for the "foreach()" method i |
|
|
I reinstalled Gallery. I got a internal server error while trying to access the gallery's configuration wizard. I had to add this...
<Directory "/path/to/your/gallery/directory">
AllowOverride Options FileInfo
</Directory>
to my access.conf file which is located in /etc/httpd/conf/ . (My data center said that for Cobalts it's better to update that file rather than the httpd.conf file). I stopped and restarted httpd to get it that to work. I could then run the gallery setup wizard. I even tested the gallery's test page and it passed the sessions test.
I uploaded the random_support.php into the gallery directory and the block_random.php into the blocks directory. I activated the block. ... And got the error.... My last resort was to upload my edited sessions.php with$_SESSIONS replacing $_HTTP_SESSION_VARS on line 55 and 56. Expecting success and got denied....
I still get the "invalid arguments for the "foreach()" method" error....
Any ideas? Thanks in advance. |
|
| Back to top |
|
|
gregwun
Beginner


Joined: Aug 04, 2003 Posts: 5
|
Posted: Fri Aug 08, 2003 4:48 pm Post subject: Re: invalid arguments for the "foreach()" method i |
|
|
Eureka! It's fixed!
I added this code
Code: › global $gallery;
to the top of the block_random.php just after <?php
So the top of the block_random.php looks like this:
Code: › <?php
global $gallery;
I found that solution in dari's post related to fluentdesigns post.
Ok... bye. And thanks dari.
Oh, and one more thing.... Since I'm using an Apple Mac I had to use the "save as" option "unix" on all the pages i edited using bbedit. |
|
| Back to top |
|
|
slackbladder
Moderator


Joined: Mar 29, 2003 Posts: 1038 Location: Cambs,UK
|
|
| Back to top |
|
|
|
|
|
|
|