0

is this possible with php? I have a login script and i need a way to check if the session exists so users can view pictures in the directory

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by diafol
0

IN your Login script how you are checking?

Using database right?

If the user has authenticated then create a session id. Wherever you want to give access to the logged in users then check for session id.

After logging out the user, destroy his session

0

IN your Login script how you are checking?

Using database right?

If the user has authenticated then create a session id. Wherever you want to give access to the logged in users then check for session id.

After logging out the user, destroy his session

how can you create a session for that person logged in to be able to view images? I mean any guest can browse and guess picture urls and see them without being logged in right now

0
if(isset($_SESSION['mysite']['user'])){
  $imgRights = 1;
}

then where the images are output to the screen:

<?php if($imgRights){?>
<img src="myimage.png" />
<?php } ?>

There are loads of ways of doing this.

Edited by diafol: n/a

0
if(isset($_SESSION['mysite']['user'])){
  $imgRights = 1;
}

then where the images are output to the screen:

<?php if($imgRights){?>
<img src="myimage.png" />
<?php } ?>

There are loads of ways of doing this.

Would that stop direct url access of images in the directory?

I've tried loads of ways to stop direct url access to images none have worked so far. I only want the images to be viewed if you're logged in.

Edited by reedd5404: n/a

0

No it wouldn't if they KNEW the url, but if they are only displayed to logged in users, they may be difficult to figure out.

To do what you want, I use a php file to display an image. The php file looks for a session variable. If it is set - show the requested image. Otherwise, show nothing or a default/alternative image.

In order to do this, I keep a list of images in a DB with an id. The id is passed to the php page thus:

<img src="image.php?id=23" />

The image.php file:

1) check for session login variable
2) get id from url
3) get filename from DB
4) create image header

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.