?
Solved

Can a session variable be accessed on a background php page the user does not see?

Posted on 2014-09-05
3
Medium Priority
?
284 Views
Last Modified: 2014-09-05
if (isset($_SESSION['user']) && $_SESSION['user'] != '') {
  $username = $_SESSION['user'];
}

Open in new window


I have a file upload form. I get a file id number from the url, and use AJAX to send it to a background php page to upload a file. I want that background php page that the user never sees to get the username from a session variable and use that name to cross check the file id from that url by checking the database to verify the file id matches with the username in the same table row.

When I try this, the session variable appears to be empty or it cannot be accessed by a background php page.

My second option would be to send in the url a user id in addition to a file id. Then access the database to be sure the two id's go together. But I think this would be less secure.

1. My question is; Is it true session variables cannot be accessed by background php pages?
2. If yes, then how might I perform a cross check without the session variable? Thanks.
0
Comment
Question by:kadin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 40307221
No, 'background' has nothing to do with it.  I use sessions on 'invisible' pages all the time.  But the page Must Always have session_start() at the top of it.  That's how PHP picks up the current session.  On several pages, I even start the session with an AJAX call.  session_start() is the key.
0
 

Author Closing Comment

by:kadin
ID: 40307230
Thanks. That didn't even occur to me.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40307237
You're welcome, glad to help.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question