Solved

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

Posted on 2014-09-05
3
278 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
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 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 83

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wamp versus xampp 4 43
myqsl update statement on phpMyAdmin 8 21
WordPress syntax 2 23
Making register page log you in after registration is complete. 2 13
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

943 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now