0

I have an example link here:

http://mydomain.com/myapp1/index.php/image/index/album/check+picture/id/1

Now I'm trying to retrieve the "1" at the very end of the url.

So far, I've tried the following code:

 $id = $_GET['id'];

But it is not working. I was used to the url having the index.php?id=1 Syntax but I'm not entirely sure how to get this one working.

UPDATE

Before accepting an answer, I wanted to add this script I used to get the entire URL of the current page:

 $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https';
    $host     = $_SERVER['HTTP_HOST'];
    $script   = $_SERVER['SCRIPT_NAME'];
    $params   = $_SERVER['QUERY_STRING'];
    $currentUrl = $protocol . '://' . $host . $script . '?' . $params;

    echo $currentUrl;

When it echoes, it only prints out:

http://www.mydomain.com/myapp1/index.php?

3
  • 1
    Are you using any framework ? This is called pretty urls. Commented Feb 27, 2014 at 5:30
  • 1
    Yes, @Rikesh. I'm using Yii Framework Commented Feb 27, 2014 at 5:40
  • possible duplicate of Yii framework: Controller/Action url & parameters Commented Feb 27, 2014 at 6:23

4 Answers 4

2

Just do this :

echo basename($_SERVER['REQUEST_URI']);
Sign up to request clarification or add additional context in comments.

2 Comments

please check my revised question
@user3278616 - and you look at mine
0

Something like this should work for you:

$id = substr($url, strrpos( $url, '/' )+1);

2 Comments

Even if the $url is not part of the script anymore? I mean, I created a link from a previous page to redirect it to the link above.
please check my revised question
-1

Get YII Documentation...

$id = Yii::app()->request->getQuery('id')

Or

$id = Yii::app()->getRequest()->getQuery('id');

Possible duplicate

http://stackoverflow.com/questions/2760869/yii-framework-controller-action-url-parameters

Comments

-2

try this....

$url = "http://mydomain.com/myapp1/index.php/image/index/album/check+picture/id/1";

$value = substr(strrchr(rtrim($url, '/'), '/'), 1);

Ref

In Yii Framework you can get value like this...

$id = Yii::app()->getRequest()->getQuery('id');

OR

$id = Yii::app()->request->getParam('id');

2 Comments

please check my revised question
@user3278616 I revised my answer according to Yii.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.