Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL clarity #25

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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