Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to get current page URL without any & parameters
Old 03-31-2010, 03:01 PM How to get current page URL without any & parameters
Super Talker

Posts: 101
Trades: 0
Not sure if my question is phrased correctly, but I want to get the current page url which for example let's say is:

http://www.mysite.com?gallery=my_pic...&place=jamaica

without any of the &'s and their values. Basically what I want is:

http://www.mysite.com?gallery=my_pics.html

Using this:

PHP Code:
        $pageURL 'http';

        if (
$_SERVER["HTTPS"] == "on") {$pageURL .= "s";}

        
$pageURL .= "://";

        if (
$_SERVER["SERVER_PORT"] != "80") {
            
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
        }
        else {
            
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
        }

        return 
$pageURL
returns the whole url, and I know I can use something like:

str_replace('&type=photos&place=jamaica', '', $pageURL);

before returning $pageURL but that's not a viabe option as I will sometimes have two & parameters and sometimes many more.

So is there a way to always strip all &'s and the values from a URL? (btw I still want to keep the ?something just not the &'s)

Last edited by Towhid; 03-31-2010 at 03:03 PM..
Towhid is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-31-2010, 03:40 PM Re: How to get current page URL without any & parameters
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Use the HTTP variables
PHP Code:
$_SERVER['HTTP_HOST'] . "/" .  $_SERVER['SCRIPT_NAME'
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?

Last edited by chrishirst; 03-31-2010 at 03:44 PM..
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-01-2010, 11:59 AM Re: How to get current page URL without any & parameters
Super Talker

Posts: 101
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Use the HTTP variables
PHP Code:
$_SERVER['HTTP_HOST'] . "/" .  $_SERVER['SCRIPT_NAME'
Ahh thanks, The forward slash wasn't necessary though.
Towhid is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to get current page URL without any & parameters
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.45620 seconds with 12 queries