Hello everybody, I am needing help... ...Lets say I have this url: www.exampledomain.com/pages/3 As you can see, there is /pages/3 I want to get the 3 and store it in a variable... Obviously $_GET['page'] won't work..What is best solution (I know of .htacess)
Hey, thanks for your reply but I don't want to use .htaccess....Is there any other way APART from .htacess, I don't know .htacess very well..
Well you need .htaccess to rewrite your URLs like this... Your question sounded like you already have those URLs and just problems getting the data out of it.
I am actually using a php framework for those types of urls yeha, I need to get the little 3 out of that url and store it in an $variable
Well, if not use .htaccess, then you can use frameworks such as symfony, zend framework or some others, they take care of extracting parameters from url. BUT if .htacess is hard for you, framework will surely be harder. Second possible solution - parse $_SERVER['REQUEST_URI']. Something like: $tokens = explode("/",$_SERVER['REQUEST_URI']); PHP: But still you'll have to use .htaccess to redirect all requests to your index.php or any other file where above code will be situated. Just like wordpress does: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> Code (markup):
Looks like I'm late with my advice. If you are using a framework, I guess there are already some functions to extract these params from url.
i agree if you are using a php framework it should have something built in. I use Zend framework occasionally and it gives me that information through $this->_request->getParam('PARAM NAME HERE') inside your "controller". obviously the framework would know that the "3" is supposed to be a "id" of some sort. so It might represent pageId, so you would say $this->_request->getParam('pageId') to get your value.