Redirecting a URL to QR code data (.vcf / VCARD) - i.e., not a URL
Asked Answered
T

1

6

I've accidentally made (and distributed) a QR code to a URL (important: not a VCARD data set like below). So now I need to redirect visits from the URL "directly" to the VCARD data:

BEGIN:VCARD
VERSION:3.0
N:Doe;John;
FN:John Doe
TEL;TYPE=CELL:54321
END:VCARD

I say "directly" in the sense that iPhones happily offer to save the contact if the URL is to a .vcf file but, based on my tests, androids don't and instead need to have the QR code go "directly" to the data set (I don't know another way to get an android to directly prompt to save the contact?).

I studied some related posts but they talk about getting the android user to first download a VCARD file or an app or generate a .vcf file which is not my situation as my URL already goes straight to a .vcf file.

I don't know for sure whether it's possible to get the android to prompt to save a contact if I return the VCARD data set through redirecting to a page with some magical PHP functions.

Because the androids don't prompt to save a contact upon visiting xyz.com/jd.vcf, I need to "redirect" that to the VCARD data set - but given that it isn't a "URL" I can't redirect to it.

Trot answered 6/1, 2023 at 1:12 Comment(5)
I'm unsure what you mean. When I hit a vcard url on my android, true it downloads a file first, but then I just have to open the file from within chrome or w/e browser on android and it prompts to save a contact. Does the iPhone skip directly to the prompt without making you download? I don't have one to testThurmanthurmann
Hi ChiliNUT. Yes, iphone goes straight into offering to save the contact. Android does the same if the QR code data is as above (see example). There may be other ways to get an android to do it - but this is the only option I’ve found. So coming back to the challenge: how can I “redirect” a URL to a non URL? I think I need the url to go to a page where PHP or JS magically achieves the same outcome as if the QR code directed the user directly to the data..?Trot
ah, I finally understand what you mean. That samsung image you posted, the qr code is not of a url, its literally the text of the vcard. I don't think there's a way to achieve the same result with a redirect, but I could be wrongThurmanthurmann
Thanks anyway chiliNUT. Please see my solution if interested =)Trot
I tried a similar approach that did not work for me: header('Content-Type: text/x-vcard'); echo file_get_contents("/path/to/vcard.vcf"); , with that approach it still prompted me to download a file first, so thats why I said I didn't think it could be done. Maybe I screwed up a header or something. Glad you got it working!Thurmanthurmann
T
1

I did it in PHP! The below works for iphone and Android, so no need to split the URL visits by device either!

# Send correct headers      
header("Content-type: text/x-vcard; charset=utf-8");

# Set variables for contact information
$family_name = "DOE";
$given_name = "JOHN";
$additional_names = "";
$prefix = "Mr";
$suffix = "";
$formatted_name = "$prefix $given_name $family_name";

# Output vCard data
echo "BEGIN:VCARD\r\n";
echo "VERSION:3.0\r\n";
echo "N:$family_name;$given_name;$additional_names;$prefix;$suffix\r\n";
echo "FN:$formatted_name\r\n";
echo "END:VCARD\r\n";
Trot answered 6/1, 2023 at 22:34 Comment(2)
This didn't work for me with Samsung ... did you test it on Samsung?Adultery
Doesn't work on android, it forces the download of a vcf file with the same name as your PHP script, which you can use to add a contact, but it doesn't automatically open the contact app as it is claimed. Device: Redmi note 10s Android version: 13Woodchuck

© 2022 - 2024 — McMap. All rights reserved.