Php session expires always when some image is not loaded on my site

I have session problem with expires,always session expires when i go to page where image is not showing or is delete from web site but exist img src code or path file to directory image?all other things is normal,but always session is destroyed when image on my site is not loaded?somebody help?

i think we’re going to need a bit more of an explanation than that… can you show us an example?

No i can’t show you but i can tell what is the problem.Problem exist when i go to page where that page contains images and that images are not loaded and when i click on some link anywhere,i don’t won’t to stay on that page,i click on next link for something and i got log off,session is expired?i don’t know why,but if on that page images are showing normal,all is ok.

Be sure session_start(); is called before ANYTHING is rendered to the web and preferably one of the first lines of code. Any “error message” being sent to the page can interfere with session being started. Although you may have some $_SESSION['key'] defined when a person logs in, this “session” can’t be read if session is not started on the page.

You may also want to plan for this missing image and have a default “No Image” png and write coding to check if the file exists, then show the file, else show a default image. Roughly like so.

$MyImage = (file_exists($MyImage) ? $MyImage : $DefaultImage);

I have it all done as you wrote but the problem is when the image is not displayed on the site, then it seems like the session is automatically lost

Have you checked the error log file?

Have you investigated why the images don’t load?

These images, is it links to images added by someone else?

If, I would check if your logout system, allow logout by GET (I.e. without the use of security token, etc.).

This was a common way to “wreck” havoc on forums almost 2 decades ago, you linked to the logout function, and the browser tried to load it as an image, and by that logged the user visiting the page out (assuming they were logged in of course).

The same can be done a lot more elaborately, where this only happens at random intervals and the rest of the time it actually shows an image.

those images exist to have been added by someone and to be system images but if they are not displayed then the session automatically disappears because the image has been deleted and displays the default icon of the deleted image,to me all users when logging in have a session, so the link does not show the password or nickname of the person

because they have been deleted, but even if they have been deleted, the session should not disappear suddenly if I click on a link on the site

Help please

A missing image isn’t going to cause the session to “disappear”. Without seeing your code, all we can do is guess.

1 Like

Something like this,if this display on my site,my session dissapear

But in my case,a missing image going to cause the session to “disappear”. ?i don’t know why

I checked but there is nothing there

session_start(); is called before anything its ok.
i didn’t put the code to have a default image if the image doesn’t show up, maybe that’s a problem

Sorry, but as @Gandalf said, it’s hard to imagine what might be causing this without seeing the code.


echo '<br/><img src="imagefolder/image.jpeg" alt="icon" height="250" width="200" />';

I put my code here,i hope you can see