Jump to content

input in form returns a string instead of php function


PHPSuperNewb

Recommended Posts

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  :wtf:

single quotes didn't work eather  :confused:

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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  :confused:

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;
}

?> 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.