Solved

grab details about server and page

Posted on 2006-11-16
6
167 Views
Last Modified: 2006-11-18
Hi

I have url's like the following and I want to break them into bits to then make links/labels etc

What do I need to grab ALL the details from a URL made like this

http://s1234:7777/webapp/eforms/abandoned-vehicles.php
IE Address / port / path / current page

Thanks
Neil
0
Comment
Question by:NeilT
  • 3
  • 3
6 Comments
 
LVL 13

Expert Comment

by:rhickmott
ID: 17961287
http://uk2.php.net/manual/en/function.parse-url.php

<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';

print_r(parse_url($url));

echo parse_url($url, PHP_URL_PATH);
?>  

The above example will output:

Array
(
    [scheme] => http
    [host] => hostname
    [user] => username
    [pass] => password
    [path] => /path
    [query] => arg=value
    [fragment] => anchor
)
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 17961297
Above will output

scheme - e.g. http
host
port
user
pass
path
query - after the question mark ?
fragment - after the hashmark #
0
 
LVL 3

Author Comment

by:NeilT
ID: 17963330
superb, many thanks!
Neil
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Author Comment

by:NeilT
ID: 17963389
sorry

just realised that doesn't actually grab the current full url first, any ideas how to get that?

neil
0
 
LVL 13

Accepted Solution

by:
rhickmott earned 500 total points
ID: 17963660
Well that's a lore more difficult unfortunately.

You can normally get the full page request by using something along the lines of.

$_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; But I don't think that will include any port usage etc.

You could use a combination of

$_SERVER['SERVER_PROTOCOL'];
$_SERVER['HTTP_HOST'];
$_SERVER['SERVER_PORT'];
$_SERVER['REQUEST_URI'];

Maybe something along the lines of

"http://" . $_SERVER['HTTP_HOST'] . ":" . $_SERVER['SERVER_PORT'] . "/" . $SERVER['REQUEST_URI'];
0
 
LVL 3

Author Comment

by:NeilT
ID: 17963689
excellent, thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now