PHP variable scoping -
i'm having trouble variable scoping in php. here's structure of code--
<?php $loader = new elload(); $sessionid = ''; $method = $_request['m']; if (strcasecmp($method, "getfile") == 0) { global $loader; $loader->load($file['text']); global $sessionid; $sessionid = $loader->getsessionid(); } if (strcasecmp($method, "extract") == 0) { $extractor = new elextract(); global $sessionid; $extractor->extract($sessionid); //$session id reason still ' ' here }
the sequence of requests client load followed extract. can tell me why $sessionid variable may not getting updated right?
you don't have declared global $...
unless you're in function. block (if, while, ...) have same scope line before.
i don't know want do, have keep $sessionid
content in real session, like:
<?php session_start(); $loader = new elload(); $_session['id'] = ''; $method = $_request['m']; if (strcasecmp($method, "getfile") == 0) { $loader->load($file['text']); $_session['id'] = $loader->getsessionid(); } if (strcasecmp($method, "extract") == 0) { $extractor = new elextract(); $extractor->extract($_session['id']); //$session id reason still ' ' here }
Comments
Post a Comment