Re: Fwd: Parsing and using URL variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Your PHP is fine.

Your URL sucks. :-)

You can't have spaces in the data, nor / nor all kinds of stuff.

Which is why you should ALWAYS call:
http://php.net/urlencode
on data before you cram it into a URL.

*then*, if you are putting that URL into HTML for a person to click
on, you need to make it kosher for HTML browser output, which means
you need:
http://php.net/htmlentities

Sample usage:

$ph = 'My Website';
$cf = 'home.htm';

$url = 'www.mywebsite.com';
$url .= '?ph=' . urlencode($ph);
$url .= '&cf=' . urlencode($cf);

echo '<a href="', htmlentities($url), '">click me</a>';



On Fri, October 20, 2006 8:35 am, andrew newman wrote:
> ---------- Forwarded message ----------
> From: andrew newman <andjnewman@xxxxxxxxx>
> Date: Oct 20, 2006 2:30 PM
> Subject: Parsing and using URL variables
> To: php-general-digest@xxxxxxxxxxxxx
>
>
> Hello
>
> I am very new to PHP and I am trying to parse the values of variables
> from a URL into a web page. to build a very simple CMS!
>
> For example if the url is
>
> www.mywebsite.com?ph=My Website&pt=Welcome Page&cf=home.htm
>
> I then have a php file that is something like this:
>
> <html>
> <head>
> <title>
> <?php $val = $_GET['ph']; echo $val;?>
> </title>
> </head
> <body>
> <b><?php $val = $_GET['pt']; echo $val;?></b>
> <p/>
> <?php $val = $_GET['cf'];  Include '$val'; ?>
> </body>
> </html>
>
> Any advice would be most welcome!
>
> Thanks Andrew
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux