Search Results

Search found 8 results on 1 pages for 'superglobals'.

Page 1/1 | 1 

  • Adding keys to superglobals in php

    - by gautam kumar
    Is there any way by which I can add keys to superglobals in php without defining the corresponding values to those key? For example: $_SESSION['key']='set';//key` automatically gets defined. But I want to do something like this add_key($_SESSION,'key')//key is added to $_SESSION array. Is it possible?

    Read the article

  • Is it safe to unset PHP super-globals if this behavior is documented?

    - by Stephen
    I'm building a PHP framework, and in it I have a request object that parses the url as well as the $_GET, $_POST and $_FILE superglobals. I want to encourage safe web habits, so I'm protecting the data against SQL injection, etc. In order to ensure users of this framework are accessing the safe, clean data through the request object, I plan to use unset($_GET, $_POST, $_REQUEST); after parsing those variables. I will document this in the method comments, and explain in the framework documentation that this is happening. My question is: Would this be desirable behavior? What are the potential pitfalls that I have not foreseen?

    Read the article

  • Possible to Dynamic Form Generation Using PHP global variables

    - by J M 4
    I am currently a fairly new programmer but am trying to build a registration page for a medical insurance idea we have which captures individual information and subsequent pieces of information about that individual's sub parts. In this case, it is a fight promoter enrolling his 15+ boxers for fight testing services. Right now, I have the site fully laid out to accept 7 fighters worth of information. This is collected during the manager's enrollment. However, each fighter's information is passed and stored in session super globals such as: $_SESSION['F1Firstname']; and $_SESSION['F3SSN3'];. The issue I am running into is this, I want to create a drop down menu selector for the manager to add information for up to 20-30 fighters. Right now I use PHP to state: if ($_SESSION['Num_Fighters'] 6) ... then display the table form fields to collect consumer data. If I have to build hidden elements for 30 fighters AND provide javascript/php validation (yes I am doing both) then I fear the file size for the document will be unnecessarily large for the maanger who only wants to enroll 2 fighters. Can anybody help?

    Read the article

  • Stop PHP from creating arrays in $_POST superglobal

    - by cdmckay
    PHP will automatically convert <input type="text" name="foo[0]" value="x" /> <input type="text" name="foo[1]" value="y" /> into $_POST['foo'] = array( 0 => 'x', 1 => 'y' ); Which is what you want most of the time. However, in this case I would like this not to happen. Is there anyway to tell PHP to not do this? I realize I could parse php://input myself, but I'd rather not do that if I can avoid it. I also don't have the option of renaming the input names.

    Read the article

  • What risks are there in using extracted PHP superglobals?

    - by Zephiro
    Hola usando estas funciones, que riesgo corro en tener problemas de seguridad, es necesesario usar extract() o hay alguna manera mejor de convertir las variables superglobales (array) en trozos de variables. Good, there is some risk in using the function extract in the superglobal variables as $_POS and $_GET, I work of the following way. There is risk of SQL INJECTION or there is an alternative to extract if ( get_magic_quotes_gpc() ) { $_GET = stripslashes( $_GET ); $_POST =stripslashes( $_POST ); } function vars_globals($value = '') { if (is_array ( $value )) $r = &$value; else parse_str ( $value, $r ); return $r; } $r = vars_globals( $_GET ); extract($r, EXTR_SKIP);

    Read the article

  • PHP $_GET and $_POST are returning empty arrays--trying to paginate SQL data

    - by George88
    I have set up the following: Database class ($db) Pagination class ($paginator) I am attempting to write a basic system to let me administrate pages. I have a page "page_manager.php" in which I include both my database class (database.php) and my pagination class (paginate.php). In my pagination class I have a function which echoes my SQL data. I've come up with a way to echo an HTML < select element with the necessary IDs, which allows me to successfully echo the corresponding results (10 per page), based on the value of the < select element. So, "1" will echo the first 10 results in the database, "2" will echo from 11-20, "3" will echo from 21-30, etc., etc.. I have added an onChange event to the < select element which will copy its value (using "this.value") to a hidden form field. I then submit this form using document.getElementById().submit(); This will then add the $_GET variable to the URL, so the URL becomes ".../?pagenumber_form=X". However, when I try to grab this value back from the URL, the $_GET['pagenumber_form'] is empty. Some code: <span style='font-family: tahoma; font-size: 10pt;'>Page #</span> <select id="page_number_selection" onchange='javascript: document.getElementById("pagenumber_form").value = this.value; document.getElementById("pagenumber").submit();'> <?php for($i = 1; $i <= $this->num_pages; $i++) echo"<option id='" . $i . "'>" . $i . "</option>"; ?> </select> <form name="pagenumber" id="pagenumber" action="" method="get"> <input type="text" name="pagenumber_form" id="pagenumber_form" /> </form> So, I've tried using $_POST as well, but the same thing happens. I want to use $_GET, for a couple of reasons: it's easier to see what is happening with my values and the data I'm using doesn't need to be secure. To recap: the $_GET variable is being added to the URL when I change the < select element, and the corresponding value gets added to the URL as: ".../?pagenumber_form=X", but when I try to use the value in PHP, for example... $page_number = $_GET['pagenumber_form']; ... I get a NULL value. :-( Can anybody help me out please? Thank you. EDIT: I've just made a discovery. If I move my print_r($_GET) to my main index page, then the superglobals are returning as expected. My site structure is like this: index.php - JavaScript buttons use AJAX HTTP requests to include the "responseText" as the .innerHTML of my main < div . The "responseText" is the contents the page itself, in this case page_manager.php, which in turn includes pagination.php. So in other words, my site is built from PHP includes, which doesn't seem to be compatible with HTTP superglobals. Any idea how I can get around this problem? Thank you :-).

    Read the article

  • How do I log the raw HTTP headers with a PHP script?

    - by php
    I'm using a cURL script to send POST data through a proxy to a script and I want to see what raw HTTP headers the cURL script is sending. List of things I've tried: echo curl_getinfo($ch, CURLINFO_HEADER_OUT) gives no output. file_get_contents('php://input') gets some HTTP headers but not all. print_r($_SERVER) also gets some HTTP headers but not all (I know this because there should be a X-Forwarded-For header and there isn't) Printing all superglobals ($_POST, $_GET, $_REQUEST, $_FILES etc) still doesn't show the raw HTTP headers. http_get_request_headers(), apache_request_headers(), $http_response_header, $HTTP_RAW_POST_DATA aren't outputting everything. Help?

    Read the article

  • PHP get "Application Root" in Xampp on Windows correctly

    - by Michael Mao
    Hi all: I found this thread on StackOverflow about how to get the "Application Root" from inside my web app. However, most of the approaches suggested in that thread can hardly be applied to my Xampp on Windows. Say, I've got a "common.php" which stays inside my web app's app directory: / /app/common.php /protected/index.php In my common.php, what I've got is like this: define('DOCROOT', $_SERVER['DOCUMENT_ROOT']); define('ABSPATH', dirname(__FILE__)); define('COMMONSCRIPT', $_SERVER['PHP_SELF']); After I required the common.php inside the /protected/index.php, I found this: C:/xampp/htdocs //<== echo DOCROOT; C:\xampp\htdocs\comic\app //<== echo ABSPATH /comic/protected/index.php //<== echo COMMONSCRIPT So the most troublesome part is the path delimiters are not universal, plus, it seems all superglobals from the $_SERVER[] asso array, such as $_SERVER['PHP_SELF'], are relative to the "caller" script, not the "callee" script. It seems that I can only rely on dirname(__FILE__) to make sure this always returns an absolute path to the common.php file. I can certainly parse the returning values from DOCROOT and ABSPATH and then calculate the correct "application root". For instance, I can compare the parts after htdocs and substitute all backslashes with slashes to get a unix-like path I wonder is this the right way to handle this? What if I deploy my web app on a LAMP environment? would this environment-dependent approach bomb me out? I have used some PHP frameworks such as CakePHP and CodeIgniter, to be frank, They just work on either LAMP or WAMP, but I am not sure how they approached such a elegant solution. Many thanks in advance for all the hints and suggestions.

    Read the article

1