Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Using PHP to pass paramters to a JSP

  • 05-03-2008 12:03pm
    #1
    Registered Users, Registered Users 2 Posts: 2,021 ✭✭✭


    Hey

    Just a quick question. I have a php page that takes some input from html fields. I want to pass these values as paramters to a JSP. Any suggestions how I would go about this?

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    You could pass them in the query string. Also have a look as jsp forms processing, you should find a solution in there.


  • Registered Users, Registered Users 2 Posts: 2,021 ✭✭✭ChRoMe


    Sorry I should have been clearer. A user inputs some details into a html form. This forms posts to a php page that does some modifications of the information submitted. I then want to post (or is it put?) these new values to a jsp page through the query string eg www.blah.com/blah.jsp?name=joe&phone=whatever

    Once this is done Im going to use header to forward the user onto a page that thanks them for their submission.

    So without any interaction from a user how can i get php to send this query string (should i be using the curl lib?) to the jsp?


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Check out the CURL library for this. Seems ideal for what you want. This allows you to call a URL from your PHP script without redirecting the user.


  • Registered Users, Registered Users 2 Posts: 2,021 ✭✭✭ChRoMe


    I've been playing around with curl and cant seem to get it to pass the paramters to the jsp. Its my first time using it so its probbably an obvious mistake in the code. I'd be grateful if anyone with any experience of using it could have a look.
      $operator = $_POST['operator'];
      
      $phone = $_POST['phone'];
      
      $params = array("phone" => "$phone", "operator" => "$operator");
      
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, 'http://example.com/Handler.jsp');
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
      curl_exec($ch);
    


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    A quick search reveals a few people have problems passing the array to curl_setopt.

    Best thing seems to be to construct the string yourself.

    So
    [php]

    $post_string = "";

    foreach($params as $k => $v) {
    $post_string .= "$k=".url_encode($v)."&";
    }

    ...

    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);

    [/php]


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    I'm not familiar with php but should the variables be enclosed in quotation marks? I've removed them below.
      $operator = $_POST['operator'];
      
      $phone = $_POST['phone'];
      
    [b]  $params = array("phone" => $phone, "operator" => $operator);[/b]
      
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, 'http://example.com/Handler.jsp');
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
      curl_exec($ch); 
    


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Yeah, it's an associative array, so the key names should be enclosed in quotes.


Advertisement