Skip to content

Commit

Permalink
Merge pull request #25 from cmbuckley/url-clarity
Browse files Browse the repository at this point in the history
URL clarity
  • Loading branch information
cmbuckley authored Apr 10, 2024
2 parents b97f775 + de58da0 commit e40ab7e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
30 changes: 27 additions & 3 deletions public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,39 @@ footer {
padding-top: var(--nav-element-spacing-vertical);
}

.success {
hgroup i {
display: block;
}

@media (min-width: 576px) {
hgroup i {
display: inline;
}
}

.url {
color: purple;
}

.url:has(+ i .scheme:hover) .scheme,
.url:has(+ i .subs:hover) .subs,
.url:has(+ i .path:hover) .path {
text-decoration: underline;
}

.path {
color: dodgerblue;
}

.success, .https {
color: green;
}

.error {
.error, .http {
color: red;
}

.warning {
.warning, .subs {
color: orange;
}

Expand Down
34 changes: 28 additions & 6 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@
}
}

function displayUrl($url, $main) {
$parts = parse_url($url);
$subdomains = preg_replace('/' . preg_quote($main, '/') . '$/', '', $parts['host']);

// the main URL
$formatted = sprintf(
'<span class="scheme %1$s">%1$s://</span><span class="subs">%2$s</span>%3$s<span class="path">%4$s</span>',
$parts['scheme'],
$subdomains,
$main,
htmlentities($parts['path'])
);

// supplementary info
$facts = [sprintf('<span class="scheme %s">%s</span>', $parts['scheme'], strtoupper($parts['scheme']))];
if ($subdomains != '') { $facts[] = '<span class="subs">subdomains</span>'; }
if ($parts['path'] != '/') { $facts[] = '<span class="path">path</span>'; }

return '<b class="url">' . $formatted . '</b> <i>(' . implode(', ', $facts) . ')</i>';
}

?>
<!doctype html>
<html lang="en">
Expand All @@ -107,14 +128,15 @@
<main class="container">
<hgroup>
<h1>Cookie Test</h1>
<p>URL: <?= $app->getUrl(); ?></p>
<p>URL: <?= displayUrl($app->getUrl(), $main); ?></p>
</hgroup>

<p>Use this to test various cookie options and how they impact which cookies are sent to different URLs, such as
<a href="https://a.<?= $main; ?>">a.<?= $main; ?></a>,
<a href="https://a.b.<?= $main; ?>">a.b.<?= $main; ?></a>,
<a href="https://<?= $main; ?>/foo"><?= $main; ?>/foo</a>, or
<a href="http://<?= $main; ?>">http://<?= $main; ?></a>.
<p>You can test various cookie options below and how they affect which cookies are sent to different URLs, such as
<a href="https://a.<?= $main; ?>"><b class="subs">a.</b><?= $main; ?></a>,
<a href="https://a.b.<?= $main; ?>"><b class="subs">a.b.</b><?= $main; ?></a>,
<a href="https://<?= $main; ?>/foo"><?= $main; ?><b class="path">/foo</b></a>,
<a href="https://<?= $main; ?>"><b class="https">https://</b><?= $main; ?></a>, or
<a href="http://<?= $main; ?>"><b class="http">http://</b><?= $main; ?></a>.
See also some <a href="https://<?= $main; ?>/quirks/">known browser quirks</a>.
</p>

Expand Down
5 changes: 4 additions & 1 deletion src/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public function asset($src) {

// get current domain
public function getHost() {
return $this->server['HTTP_HOST'];
return filter_var($this->server['HTTP_X_FORWARDED_HOST'] ?? '', FILTER_VALIDATE_DOMAIN, [
'options' => ['default' => $this->server['HTTP_HOST']],
'flags' => FILTER_FLAG_HOSTNAME,
]);
}

// get top-level domain
Expand Down

0 comments on commit e40ab7e

Please sign in to comment.