Hi Can I do this: $file="articledetails.php"; include('$file'); I really need it or something similar to make my pages more dynamic
now i'm using this code as the next step: function membersOnly() { error_reporting(E_ALL); ini_set('display_errors', true); if (!$_SESSION['logged']) { $_SESSION['log_to'] = $_SERVER['REQUEST_URI']; session_write_close(); { $file="login.php"; header('Location: message.php'); } die(); } } PHP: and message.php has the following code on line 67: <? include "$file"; ?> PHP: now it is redircted to message.php but the login form is not shown in it. instead it prompts: Notice: Undefined variable: file in g:\programs(2)\easyphp1-8\www\ha\previous\new folder\htdocs\message.php on line 67 Warning: main(): Failed opening '' for inclusion (include_path='.;G:/Programs(2)/EasyPHP1-8\php\pear\') in g:\programs(2)\easyphp1-8\www\ha\previous\new folder\htdocs\message.php on line 67
Once you have moved page $file will have not be defined. store the value of $file in a session variable or include it at the end of your message. You might need to call session_start depending upon your setup e.g. in function membersOnly() add session_start(); $_SESSION['file'] = "login.php"; PHP: and in message.php <? include "$_SESSION['file']"; ?> PHP: although I'm not sure if you can include a session variable you might need to put it into a local variable first e.g. <? $file=$_SESSION['file'] include "$file"; ?> PHP:
You can include files in session variables. But your example would throw a parse error. Just remove the double quotes or put the variable between curly brackets.
thanks for your reply I tried it now but it seem it's not working. it prompts: Notice: Undefined variable: _SESSION in g:\programs(2)\easyphp1-8\www\ha\previous\new folder\htdocs\message.php on line 67 Warning: main(): Failed opening '' for inclusion (include_path='.;G:/Programs(2)/EasyPHP1-8\php\pear\') in g:\programs(2)\easyphp1-8\www\ha\previous\new folder\htdocs\message.php on line 67
You need to add session_start() at the top of your page to access $_SESSION variables. And both ways I said would work. include "{$_SESSION['file']}"; // Or include $_SESSION['file']; PHP:
Hi this code solved it: function membersOnly() { error_reporting(E_ALL); ini_set('display_errors', true); if (!$_SESSION['logged']) { $_SESSION['log_to'] = $_SERVER['REQUEST_URI']; session_write_close(); session_start(); $_SESSION['file'] = "login.php"; include 'message.php'; die(); } } PHP: and in message.php: <? include $_SESSION['file']; ?> PHP: it shows the login form now. but it prompts another error upon login: Fatal error: Call to a member function on a non-object in g:\programs(2)\easyphp1-8\www\ha\previous\new folder\htdocs\login.php on line 36 this error does not occur when I use login.php alone for logging in. line 36 begins as: if ($user->_checkLogin($processed['username'], $processed['password'], $remember)) { if (isset($_SESSION['log_to'])) { redirect($_SESSION['log_to']); } else { redirect('account.php/'); } } else { failed($form); } PHP:
by the way, here: $db = db_connect(); $user = new User($db); PHP: User is a class with over 260 lines. there, the function checklogin: function _checkLogin($username, $password, $remember) { $md5pass = "'" . md5(substr($password, 1, -1)) . "'"; $sql = "SELECT * FROM member WHERE " . "(username = $username) AND " . "(password = $md5pass) AND " . "(permission != '00-deny')"; $result = $this->db->getRow($sql); if (is_object($result)) { $this->_setSession($result, $remember); return true; } else { $_SESSION['login']--; $this->_logout(); return false; } } PHP:
Avoid using double quotes where you can.. They take longer to parse because everything is looked at, with single it is what it is.. nothing else needs to be done.