Re: [PHP] getting around the undefined index



On 11/27/06, Ross <ross@xxxxxxxxxxxxx> wrote:

I have not found a satisfactory way of doing this yet!!!!


$text = $_REQUEST['text_size'];
if ($text) {
echo $text;
}


I send the $text_size variable to the browser with lines like...

<a href="<? $_SERVER['PHP_SELF']; ?>?text_size=small" class="size1"
id="one">A</a>


When the page initially loads I get a undefined index error as it does not
exist but is there a way of wrapping in in a switch statement or funtion so
the variable is only used when $_REQUEST['text_size']; actually exists.


Ross

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Try this:

$text = (isset($_REQUEST['text_size']))
? preg_replace("/\W/", "", $_REQUEST['text_size'])
: 'your-default-value';

This will say $text equals a cleaned version of
$_REQUEST['text_size'] if it exists. If it does not exist then use
'your-default-value'.

If you use any data from external resources always remember to
sanitize the data. Otherwise you will end up with XSS vulnerabilities
in your scripts. This is _very_ important.
.



Relevant Pages

  • Re: Browser support was Re: New Group for DesignBAIS
    ... Ross Ferris wrote: ... > In terms of general BI (Browser Independence), ... > old browsers you can't even rely on frames being present! ...
    (comp.databases.pick)
  • Re: letting a search engine see image text?
    ... David E. Ross wrote: ... Imagine a blind person using an audio browser. ... browser also reads the text from ALT attributes. ...
    (comp.infosystems.www.authoring.html)
  • Re: [PHP] outputing image part 2
    ... Ross wrote: ... echo $height = imagesy; ... Chances are you're getting an error message, but because you're telling the browser it's an image the browser is trying to display it as an image. ...
    (php.general)
  • Re: DesignBAIS/Dave Bryant
    ... To Ross: ... I said browser because I assumed DB runs in browser? ... From telnet session or what? ... window. ...
    (comp.databases.pick)
  • Re: [PHP] getting around the undefined index
    ... Ross wrote: ... echo $text; ... I send the $text_size variable to the browser with lines like... ... When the page initially loads I get a undefined index error as it does not exist but is there a way of wrapping in in a switch statement or funtion so the variable is only used when $_REQUEST; ...
    (php.general)