Results 1 to 7 of 7

Thread: Server Variables

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    144

    Server Variables

    Hey all

    Need some help with some server variables....

    My problem is i have a textbox on a html page called page1.html that when an sql query is placed in to the textbox that SQL query will display the relevent data on a PHP page called page2.php.

    i have the page1.html pass the data using the GET method, on page2.php i want to grab the information passed over using the GET method using server variables... so far i have the following code

    page2.php
    Code:
    <?php 
    
    $input = $_SERVER['QUERY_STRING'];
    
    echo ("{$input}")
    ?>
    This grabs the information that was entered in the textbox:

    textarea=SELECT+*+FROM+tbl_Students+WHERE+DegreeID+%3D+1&Submit=Submit

    what i want to do now is return the text to it's original form

    SELECT * FROM tbl_Students WHERE DegreeID = 1

    How would i do this?

    thanks
    Last edited by JamesBowtell; Mar 9th, 2006 at 08:28 AM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    144

    Re: Server Variables

    hey i have managed to get rid of the characters to return the string to it's original state using the following code:

    Code:
    <?php 
    $input = $_SERVER['QUERY_STRING'];
    $input = str_replace('+', ' ', $input);
    $input = str_replace('%3D', '=', $input);
    $input = str_replace('textarea=', '', $input);
    $input = str_replace('&Submit=Search', '', $input);
    echo ("{$input}")
    ?>
    nut i can imagine the code i'm using will not be the best solution to the problem can anyone suggest a better way of taking out the original variable?

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Server Variables

    urldecode($_SERVER['QUERY_STRING']);

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    144

    Re: Server Variables

    cool that replaced the + and % but is there anothe method other than

    $input = str_replace('textarea=', '', $input);
    $input = str_replace('&Submit=Search', '', $input);

    to remove the textarea= and &Submit=Search

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Server Variables

    The variables passed by the Get request are in the $_GET superglobal array so you can just use:

    urldecode($_GET['textarea'])

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    144

    Re: Server Variables

    this tutorial is ment to teach us how to use the server variables to grab the string and remove the characters automatically without using the POST or GET method

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Server Variables

    Oh, well you didn't say that, I suggest a preg pattern would probably be simplest

    urldecode(preg_replace('#textarea=(.*)&#i', '$1', $_SERVER['HTTP_REQUEST']));

    Unless you can get away with $_REQUEST or $HTTP_REQUEST_VARS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width