Jump to content

Recommended Posts

I'm making a Photo system for a high school teacher. I have the following files (there's more but...):

 

./admin/index.php

./system/session.php

./index.php

 

Both index.php files include session.php (the paths are correct). When I point my browser to http://192.168.1.131/photos/index.php it loads fine with no problems. But if I go to http://192.168.1.131/photos/admin/index.php it says that it's used it's allotment of 16 MB, so I increased it to 32MB, and I still get the error. The specific error is:

 

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 19456 bytes) in /var/www/photos/system/session.php on line 200

 

At line 200 is set_cookie (or setcookie whichever it is) and it doesn't actually run that code, it exists in a login function. I was wondering how to find out what's supposedly using all my ram.

Are you resizing images on the fly? That can eat up allot of resources.

 

Nope. I do do image resizing but not when viewing ./admin/index.php The thing is ./admin/index.php and ./index.php parse the same files; ./index.php uses for memory (./admin/index.php isn't finished), but I get the error on ./admin/index.php

You are setting cookies at line 200?  May want to rethink your logic.

 

Ahem:

 

At line 200 is set_cookie (or setcookie whichever it is) and it doesn't actually run that code, it exists in a login function. I was wondering how to find out what's supposedly using all my ram.

 

Then you might want to explain exactly what your code does. Otherwise, were just guessing.

 

If you like I could upload the code into a tar.gz file and upload a database dump.

Update:

 

I made a somewhat empty file in ./admin/ called test.php:

 

<?php

include ("../system/session.php");

?>

 

And I get:

 

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 19456 bytes) in /var/www/photos/system/session.php on line 279

 

So the code at that line is not relevant. In test.php I don't even make any instances, and none are made in the classes that are included is session.php

All right, I'll upload the source code and the sql database. In the photos_users table the password is encrypted once with md5.

 

Any other tidbits about security would be helpful too.

 

[attachment deleted by admin]

I have downloaded and ran your code, index.php worked fine as you said, however for admin/index.php it did take a while to load and then nothing happened after a couple of secounds. After doing a lot of commenting/uncommenting of lines I narrowed it down to the following line in system/sessions.php

 

include ("settings.php");

 

For some reason PHP would crash, I got no error messages, just plank page. I found this strange as I have error_reporting set to E_ALL and display_errors enabled. Once I commented that line out everything worked fine, and I got a screen full of errors. Next I decided to copy the code in setting.php to system/session.php and everything worked nicely.

 

So my conclusion is to do with how PHP is trying to include files. Maybe you should rethink your file structure.

and you didn't include the code for either one of those pages.

 

Wha?

 

I have downloaded and ran your code, index.php worked fine as you said, however for admin/index.php it did take a while to load and then nothing happened after a couple of secounds. After doing a lot of commenting/uncommenting of lines I narrowed it down to the following line in system/sessions.php

 

include ("settings.php");

 

For some reason PHP would crash, I got no error messages, just plank page. I found this strange as I have error_reporting set to E_ALL and display_errors enabled. Once I commented that line out everything worked fine, and I got a screen full of errors. Next I decided to copy the code in setting.php to system/session.php and everything worked nicely.

 

So my conclusion is to do with how PHP is trying to include files. Maybe you should rethink your file structure.

 

Is PHP trying to find settings.php in the ./admin folder? Whenever I make a website in PHP I get confused with file paths, and how PHP uses them. Got any other suggestions regarding code? Improvements, bad ideas?

 

I changed these lines:

 

include ("../system/session.php");
include ("system/admin_menu.php");

 

to this:

 

chdir ("../system");
include ("../system/session.php");
chdir ("../admin");
include ("system/admin_menu.php");

 

and now it works, albeit a bit of a kludge.

Na, do not use chdir.

 

I recommend you setup a few constants in session.php, call these BASE and ADMIN_BASE like so:

define('SYS', dirname(__FILE__));
define('ADMIN_SYS', dirname(SYS) . '/admin/system');

 

When ever you include a file from system directory, do

include SYS . '/file.php';

To include a file from admin system directory, do

include ADMIN_SYS . '/file.php';

 

You'll have to use a relative path though to include system/session.php as that is where the constants are defined.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.