Re: reading a URL...
| From: | CC Zona | Date: | Mon, 26 Mar 2001 17:51:24 +0000 |
| Subject: | Re: reading a URL... | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-7838@lists.php.net to get a copy of this message | ||
In article <85256A1B.00507A29.00@Notes_SMTP.risk.sungard.com>,
Tristan.Pretty@risk.sungard.com wrote:
> Is it Possible, in PHP to read a URL?
>
> What I am trying to do is this...
> I have many news stories in a database, and a single static news page, that
> calls the story, and the corresponding headline.
> I have looked about on-line, and seen a common URL,...
>
> http://www.arandomsite.com/news_story.php?id=123
>
> I have adopted this method, and it only displays the top most story in my
> database, no matter what news ID I use.
>
> Can I get the ID number from the URL?, and then pass that to the SQL
> statement?
Yes to both, and quite easily. All the variables passed in a GET request
(which is what the url is) will automatically be made available in the
$HTTP_GET_VARS associative array. So variable "id" is at
$HTTP_GET_VARS['id']. In addition, if the configuration setting
"register_globals" is turned on, the variable will also be accessible
simply as $id.
So in the script news_story.php, you could write a query string like, for
example:
"SELECT article_text from story_table where id=$id"
or
"SELECT article_text from story_table where id=" .
$HTTP_GET_VARS['id']
See <http://www.php.net/manual/en/language.variables.external.php>
--
CC