PHPSuperNewb Posted May 17, 2011 Share Posted May 17, 2011 ok so this problem has been laughing at me for quite some time now :-\ I tryed using some inline php in a form to pass it to my login script. The problem is that whenever the form gets submitted the variable r doesn't contain the actual microtime but it contains the inline php as a string: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Snitch</title> <link rel="stylesheet" type="text/css" href="templates/css/snitch1440x900.css" /> </head> <body> <div id="login-achtergrond"> <div id="login"> <form action="." id="loginform" name="login" method="post"> <input type="hidden" name="actie" value="Login"></input> <input type="hidden" name="r" value="<?php echo microtime();?>"></input> <input type="text" id="gebruikersnaam" name="gebruikersnaam" value="" style="opacity:0.7;filter:alpha(opacity=70)"></input> <input type="password" id="paswoord" name="paswoord" value="" style="opacity:0.7;filter:alpha(opacity=70)"></input> <input id="aanmelden" type="submit" name="submit" value="" style="opacity:0;filter:alpha(opacity=0)"> </form> </div> <div id="registreer"> </div> </div> </body> </html> the $_POST['r']; contains "<?php echo microtime();?>" instead of for example: 0.53192500 1305636839 does someone know what I am doing wrong here? I also tryed doing it like this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Snitch</title> <link rel="stylesheet" type="text/css" href="templates/css/snitch1440x900.css" /> </head> <body> <div id="login-achtergrond"> <div id="login"> <form action=".r=<?php echo microtime();?>" id="loginform" name="login" method="post"> <input type="hidden" name="actie" value="Login"></input> <input type="text" id="gebruikersnaam" name="gebruikersnaam" value="" style="opacity:0.7;filter:alpha(opacity=70)"></input> <input type="password" id="paswoord" name="paswoord" value="" style="opacity:0.7;filter:alpha(opacity=70)"></input> <input id="aanmelden" type="submit" name="submit" value="" style="opacity:0;filter:alpha(opacity=0)"> </form> </div> <div id="registreer"> </div> </div> </body> </html> both $_POST and $_GET contains a string instead of the actual microtime single quotes didn't work eather Quote Link to comment https://forums.phpfreaks.com/topic/236625-input-in-form-returns-a-string-instead-of-php-function/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 17, 2011 Share Posted May 17, 2011 Is your form a .php page that would be parsed by the php language when it gets requested? Are you browsing to the URL of the page (http://localhost/form.php) or to it as a local file in your browser? Quote Link to comment https://forums.phpfreaks.com/topic/236625-input-in-form-returns-a-string-instead-of-php-function/#findComment-1216448 Share on other sites More sharing options...
PHPSuperNewb Posted May 17, 2011 Author Share Posted May 17, 2011 My form as in the html that I just posted or the login page? if you meant what I have posted then no its a .tpl file if it's the login page then yes. what would I need to do to make sure it works in the .tpl file? and yes I'm browsing to the url. Quote Link to comment https://forums.phpfreaks.com/topic/236625-input-in-form-returns-a-string-instead-of-php-function/#findComment-1216452 Share on other sites More sharing options...
PFMaBiSmAd Posted May 17, 2011 Share Posted May 17, 2011 Php is a server side scripting language. Unless your php code is inside of a file that is parsed as a php code file on the server, the php code in it won't be executed. Quote Link to comment https://forums.phpfreaks.com/topic/236625-input-in-form-returns-a-string-instead-of-php-function/#findComment-1216461 Share on other sites More sharing options...
PHPSuperNewb Posted May 17, 2011 Author Share Posted May 17, 2011 I have this file called class.Handler_Login.php <?php class Handler_Login extends Actie_Handler { function __construct($actie_handle) { parent::construct($actie_handle); $this->actie = $actie_handle; } function secured_handler() { if ($this->sessie->check_sessie() == false) { if (isset($_POST['r'])) { $paswoord = $_POST['paswoord']; $gebruikersnaam = $_POST['gebruikersnaam']; $login = $this->dbh->Login($gebruikersnaam, $paswoord); if ($login == true) { $this->sessie->set('gebruikersnaam', $gebruikersnaam); $this->view->toonHome(); $this->view->toon(); exit; } if ($login == false) { echo "U bent niet ingelogd"; exit; } } if (!isset($_POST['r'])) { $this->view->toonLogin(); $this->view->toon(); exit; } } if ($this->sessie->check_sessie() == true) { $this->view->toonHome(); $this->view->toon(); } } } ?> and this file called login.tpl: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Snitch</title> <link rel="stylesheet" type="text/css" href="templates/css/snitch1440x900.css" /> </head> <body> <div id="login-achtergrond"> <div id="login"> <form action="." id="loginform" name="login" method="post"> <input type="hidden" name="actie" value="Login"/> <input type="hidden" name="r" value="<?php echo microtime();?>"/> <input type="text" id="gebruikersnaam" name="gebruikersnaam" value="" style="opacity:0.7;filter:alpha(opacity=70)"/> <input type="paswoord" id="paswoord" name="paswoord" value="" style="opacity:0.7;filter:alpha(opacity=70)"/> <input id="aanmelden" type="submit" name="submit" value="" style="opacity:0;filter:alpha(opacity=0)"/> </form> </div> <div id="registreer"> </div> </div> </body> </html> About half a week ago it displayed the microtime inside my browser like it should. I have no idea what I have changed since then to make it not work anymore. It doesn't display anything. So I debugged my script through nusphere and it told me that the variable r contains "<?php echo microtime();?>" instead of the actual microtime. Thats how I've found out about this. If you want I can post the entire script? Allthough it doesn't have a lot to do with it I think :S EDIT: Hmmm I remember myself saving the variable r inside a session and later returned it inside my script.. I think it got something to do with that... Not sure though :S Testing it right away Quote Link to comment https://forums.phpfreaks.com/topic/236625-input-in-form-returns-a-string-instead-of-php-function/#findComment-1216480 Share on other sites More sharing options...
wildteen88 Posted May 17, 2011 Share Posted May 17, 2011 How does your script load login.tpl? If you are using include/require then the PHP code within login.tpl will be executed. If you're using fopen/fread or file_get_contents() then the PHP code will not be executed and it'll returned as text. Quote Link to comment https://forums.phpfreaks.com/topic/236625-input-in-form-returns-a-string-instead-of-php-function/#findComment-1216557 Share on other sites More sharing options...
PHPSuperNewb Posted May 17, 2011 Author Share Posted May 17, 2011 This is my view_manager: <?php class view_beheer { private $tpl; function __construct() { } function toonStatus() { $status = file_get_contents("templates/status.tpl"); $this->tpl = str_replace("%content%", $status, $this->tpl); } function toonLogin() { $this->tpl = file_get_contents("templates/login.tpl"); } function toonHome() { $this->tpl = file_get_contents("templates/home.tpl"); } function toon() { echo $this->tpl; } } ?> In my login I call my view object to show my templates. The view object is created in my action_handler. <?php abstract class Actie_Handler { protected $sessie; protected $view; protected $dbh; function construct() { $this->sessie=new Sessie(); $this->view=new view_beheer(); $this->dbh=new DatabaseHelper(); } abstract function secured_handler(); } ?> It seems like I"m using file_get_contents() :S The strange thing is that it did display properly half a week ago And I have no idea that I had changed that since then :S might something like this be possible instead? (Haven't tryed it though): <?php $string = get_include_contents('templates/status.tpl'); $this->tpl = str_replace("%content%", $string, $this->tpl); function get_include_contents($filename) { if (is_file($filename)) { ob_start(); include $filename; return ob_get_clean(); } return false; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/236625-input-in-form-returns-a-string-instead-of-php-function/#findComment-1216653 Share on other sites More sharing options...
PHPSuperNewb Posted May 18, 2011 Author Share Posted May 18, 2011 It seems to have worked Thanks for all the help guys! Quote Link to comment https://forums.phpfreaks.com/topic/236625-input-in-form-returns-a-string-instead-of-php-function/#findComment-1216874 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.