Hey all,

Got a tricky little problem here:

I wrote a bookmarklet and a php script to email the current url of the page I am on to myself. The bookmarklet looks like this:

javascript: var url = window.location.href; var user = 'myemail@email.com';window.open(myserver.com/mailurl.php?url=" + url + "&user="+ user);

The php script looks like this:

<?php

$url = $_GET["url"];
$user = $_GET["user"];
$subject = $_GET["title"];
$headers = 'From: MailURL' . "\r\n" . 'X-Mailer: PHP/' . phpversion();

if (mail($user,$subject,$url,$headers)) {
	echo("Mailed $url to $user");
} else {
	echo("Failed to email $url to $user");
}
?>

Works great!

...

for simple urls like yahoo.com, google.com etc.

My issue is when I try to pass the php script a dynamic url (ex: yahoo.com/newstory/story.php?stuff=morestuff&more=opinion)

the php script will mangle the passed variable into this:

yahoo.com/newstory/story.php?stuff=morestuff

leaving off the last part of the url.

Any ideas?

Thanks!

PS: I am aware that there are free programs out there to sync bookmarks/probably do the exact same thing I'm trying to do, but this project is just for kicks.

hrmmm. a shot in the dark, but have you tried http://us.php.net/urlencode urlencode on the $url? if not, have you verified that the url is getting passed correctly? Initial thoughts without actually trying anything

Member Avatar for kingben
javascript: var url = encodeURIComponent(window.location); var user = 'myemail@email.com';window.open("myserver.com/mailurl.php?url=" + url + "&user="+ user);

Am not sure, but try the above snippet once


Ok, verified!! .... the above one is working great!

hrmmm. a shot in the dark, but have you tried http://us.php.net/urlencode urlencode on the $url? if not, have you verified that the url is getting passed correctly? Initial thoughts without actually trying anything

Hey kireol,

I did actually. However, PHP manual told me that when you $_GET a variable like I have done in my script it automatically urlencodes it.

I also tried rawurldecode just for fun, but no luck.

javascript: var url = encodeURIComponent(window.location); var user = 'myemail@email.com';window.open("myserver.com/mailurl.php?url=" + url + "&user="+ user);

Am not sure, but try the above snippet once


Ok, verified!! .... the above one is working great!

Okay, stand by all, I'm going to try this out...

UPDATE: It works! Thanks for both of your prompt responses. I'll post a link to my finished project in a bit.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.