Kalinin
Kalinin

Reputation: 2519

Get address bar without parameters

Help me please get the value of the address bar of browser without the parameters passed. Without the use of regular expressions and string functions. You can do this? (I use php on apache).

enter

http://dev.mazda-parts.ru/catalogue/?spattern=1

exit

http://dev.mazda-parts.ru/catalogue/

Upvotes: 0

Views: 988

Answers (3)

user47322
user47322

Reputation:

You say that you want the URL of the last page, which can be found in the $_SERVER['HTTP_REFERER'] variable.

Beware that this value is not reliable as it can be freely changed by the client.

If you want a more accurate way of finding the last page, you can use sessions. Here's an example:

session_start();
$last_page = $_SESSION['pageurl'];
$_SESSION['pageurl'] = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URL'];

// $last_page now contains a more reliable value for the last url

Upvotes: 0

erenon
erenon

Reputation: 19118

Take a look at the $_SERVER superglobal.

<?php
//example
echo $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URL'];

Upvotes: 2

Your Common Sense
Your Common Sense

Reputation: 157880

parse_url() can help you, or some of the php string functions, like strtok()

Upvotes: 1

Related Questions