Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Mobile phone headers PHP example
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=yes, minimum-scale=1.0">
<title>And your phone number is...</title>
body {
font: 17px sans-serif;
color: #444;
margin: 20px;
$headers = apache_request_headers();
foreach ($headers as $header => $value) {
if ($header == 'x-up-calling-line-id') {
$phone_number = $value;
if (isset($phone_number)) {
echo "<p>Your phone number is:</p><h1>$value</h1><p>Did you know that this number is sent to <strong>every</strong> website you visit (when not using Wi-Fi)?</p>";
} else {
echo '<p>No phone number found. Make sure Wi-Fi is turned off and <a href="./">try again</a>.</p>';
<p><a href="">More info here</a>.</p>
<p>Try <a href="">this demo</a> by <a href="">@lewispeckover</a>.</p>
<p><a href="">Source code for this page</a>.</p>

This comment has been minimized.

Copy link

@cubiq cubiq commented Jan 25, 2012

this is pretty scary...

PS: I believe you can just do like so
if ( !empty($headers['x-up-calling-line-id']) ) $phone_number = $value;


This comment has been minimized.

Copy link

@jackuzzy jackuzzy commented Feb 2, 2016

The sentence:
$headers = apache_request_headers(); foreach ($headers as $header => $value) { if ($header == 'x-up-calling-line-id') { $phone_number = $value; break; } }
Is not guaranteed it will work.
You can simply do:
$header = apache_request_headers(); if(isset($header['x-up-calling-line-id']) && !empty($header['x-up-calling-line-id'])){ $phone_number = $header['x-up-calling-line-id']; }else{ $error_phone_number = "Phone number missing...!"; }

Using this technique, saves time, does not fail when comparing 2 strings.
By the way, a safer and more proper way to compare 2 strings is to use strcmp. It returns 0 if both strings are identical, otherwise, return 1.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment