My site runs on php and mysql. Each page is static although the "url", "post-id" and "keyword" is stored in mysql server. Now my aim is to create a "relevant articles" column that will display relevant articles by fetching the url or id of the page and then using the matching keywords. But I can not find a way to fetch the current page id or url from my static url. Is there any solution to this?
Asked
Active
Viewed 152 times
-1
-
what do you mean, "static url"? `example.com/path/to/static.php`? – Marc B Jun 06 '14 at 15:05
-
Yes, exactly. Like "example.com/blog/name-of-page/" – Susan Jun 06 '14 at 15:06
-
1possible duplicate of [Get the full URL in PHP](http://stackoverflow.com/questions/6768793/get-the-full-url-in-php) – Itay Gal Jun 06 '14 at 15:08
-
1google for "php pretty url mod_rewrite", this question is way too broad. you should read the rules for posting. – NDM Jun 06 '14 at 15:08
-
There has to be some connection between `/blog/name-of-page/` and the data in your database, but we have no idea what it is as we can't see any of your code. – Quentin Jun 06 '14 at 15:09
-
1you can't check `$_SERVER["REQUEST_URI"]` or any of the other "page id" things PHP already provides? – Marc B Jun 06 '14 at 15:09
-
Sorry I didn't know this was such a broad topic. Thank you for the solution. – Susan Jun 06 '14 at 15:10
2 Answers
0
You can get different parts of the URL this way:
$url = parse_url($_SERVER["REQUEST_URI"]);
or
$url = parse_url('http://your/static/url/goes/here');

bancer
- 7,475
- 7
- 39
- 58
0
You should have a list of which static URLs go with which page IDs stored somewhere (likely in a database table, since you're using MySQL). To find out which page ID is requested, just do another lookup on this list, this time to find the page ID based on the page URL that you already have (in $_SERVER["REQUEST_URI"]
).

Brilliand
- 13,404
- 6
- 46
- 58