tags:

views:

26

answers:

2

Hi friends, Good day. I am having the following code snippet in init.php.

<?php
include_once("config.php");
include_once(__SITE_PATH . 'view/' . $_REQUEST['page'] . EXT);

$loginobj = new $_REQUEST['page']($_REQUEST['billingentitynuber']);
$text = $loginobj->$_REQUEST['content']();
echo $text;
?>

In Jquery I am having the function Jquery_event.js

$("#entertoapp").click(function()
{         
  alert($("#btval").val());
  $.ajax({
    type: "POST",
    url: "init.php?page=processing&content=enterintoapplication&btval=" + $("#btval").val(),

    success: function(msg) {
      alert(msg);
      if(msg==1)
        window.location.href='index.php?page=processing&content=mycontent';
    }
  });
});

In processing.php I am having

<?php
class processing
{
  public function enterintoapplication()
  {
    global $billingentityname;
    $_SESSION['btval'] = $billingentityname;
    echo $billingentityname;
  }
}
?>

My problem is I am getting all the parameters in the init.php. But when I call a function I need to get in the processing.php in the enterintoapplication function (i.e. I am expecting btval in the enterintoapplication function). How can I achieve this? I tried to get $_REQUEST['btval'] within the function. But I didn't get.

+1  A: 

Try assigning the values to variables, for example this works for PHP 4:

class processing
{
  function enterintoapplication()
  {
    echo "hello";
  }
}

$className="processing";
$functionName="enterintoapplication";

$loginobj=new $className();
$text=$loginobj->$functionName();
echo $text;

Paste it here to verify it works: http://writecodeonline.com/php/

Pls,pay attention to "$functionName", here it keeps the "$".

Nevertheless, for security reasons, you should be attentive to what people can do if they change the value "page".

netadictos
A: 

I don't understand your problem correctly, but with some general information, you should get out of this.

$_REQUEST is a superglobal, that means that variable will always be accessible from everywhere within your script. If your problem is you can't find the btval variable that was in your URL, you are doing something else wrong. If your url=http://someUrl/test.php?btval=banana you should always get banana if you evaluate $_REQUEST['btval']. $_SESSION is another superglobal to access the PHP session, and has nothing to do with URL variables.

My guess: Try changing

$_SESSION['btval'] = $billingentityname;

into

$billingentityname = $_REQUEST['btval'];

In that case, your real mistake was that you've put the two variables in this assignment in the incorrect order. $a = $b means: put the contents of $b into $a.

Pelle ten Cate