Author Topic: Spaces in names creating problems in links  (Read 2521 times)

paulbeestonuk

  • Posts: 26
    • View Profile
Spaces in names creating problems in links
« on: March 16, 2007, 09:15:48 pm »
Hi,
I have a sign-up list where I ask people for their first name and email address and sometimes they enter more than one name with a space between.
Here is the problem:
In an email I send them they can subscribe to another list though a text link in the email and if their name has a space the link is broken.
Any help would be appreciated.
Paul.

DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
Spaces in names creating problems in links
« Reply #1 on: March 17, 2007, 03:54:45 am »
Hi Paul,

This happens because ListMail message codes cannot currently "urlencode" spaces and other special characters for use in URLs.

What you can do is use the users' unique ID and a small custom script to sign the user up to the desired lists.

1. Set up a message code of the type "Users Unique ID", ie "!uid".

2. In your message, use this:
http://example.com/mail/join-now.php?u=!uid

3. Create a file named join-now.php in your ListMail folder containing the following code:
Code: [Select]
<?php// place this file in your LM folder// list to subscribe to$list = '1';// end config// include LM stuffinclude('./config.php');include('./admin.php');// get LM email,fname,lname based on UID$u = $_GET['u'];if(!$u) exit('error: uid not provided');list($em,$fn,$ln)=mysql_fetch_row(mysql_query("select email,fname,lname from lm_users where uid = '".addslashes($u)."';"));if(!$em) exit('error: uid not found');// get listmail pathlist($lmp)=mysql_fetch_row(mysql_query("select listmailpath from lm_config"));// forward the user with urlencoded vars to signup.php, so custom HTML, etc. is shownheader('Location: '.$lmp.'signup.php?email='.urlencode($em).'&fname='.urlencode($fn).'&lname='.urlencode($ln).'&list='.$list);?>

Regards
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting

paulbeestonuk

  • Posts: 26
    • View Profile
Can the list number be a parameter too?
« Reply #2 on: March 17, 2007, 04:08:23 am »
Thanks Dean
Could I pass in the list number as a parameter too?
Cheers,
Paul.

DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
Spaces in names creating problems in links
« Reply #3 on: March 17, 2007, 05:01:57 pm »
Paul,

Probably, yes.  Simply remove
Code: [Select]
$list = '1';
and use a link:
http://example.com/mail/join-now.php?u=!uid&list=1

or shorten it further (I like to)
Code: [Select]
$list = $l;
and use a link:
http://example.com/mail/join-now.php?u=!uid&l=1

or you could even use ModRewrite in .htaccess of your root web...
Code: [Select]
RewriteEngine On
RewriteRule ^/join/(.*)/(.*)$ /mail/join-now.php?u=$1&list=$2 [L]


and use a link like:
http://example.com/join/!uid/1

:)

Regards
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting

paulbeestonuk

  • Posts: 26
    • View Profile
Nearly there - but errors
« Reply #4 on: March 17, 2007, 11:58:27 pm »
Hi Dean,

Here is my modified script:
<?php
// add-to-list.php
// include LM stuff
include('./config.php');
include('./admin.php');

// get LM email,fname,lname based on UID
$u = $_GET['u'];
$list = $_GET['l'];
if(!$u) exit('error: uid not provided');
if(!$list) exit('error: list number not provided');

list($em,$fn,$ln)=mysql_fetch_row(mysql_query("select email,fname,lname from lm_users where uid = '".addslashes($u)."';"));
if(!$em) exit('error: uid not found');

// get listmail path
list($lmp)=mysql_fetch_row(mysql_query("select listmailpath from lm_config"));

// forward the user with urlencoded vars to signup.php, so custom HTML, etc. is shown
header('Location: '.$lmp.'signup.php?email='.urlencode($em).'&fname='.urlencode($fn).'&lname='.urlencode($ln));
?>

Here are the errors I am getting:
Warning: Variable passed to each() is not an array or object in /home/httpd/vhosts/mailist.co.uk/httpdocs/mail/signup.php on line 27

Warning: reset(): Passed variable is not an array or object in /home/httpd/vhosts/mailist.co.uk/httpdocs/mail/signup.php on line 63

Warning: Variable passed to each() is not an array or object in /home/httpd/vhosts/mailist.co.uk/httpdocs/mail/signup.php on line 65

Warning: reset(): Passed variable is not an array or object in /home/httpd/vhosts/mailist.co.uk/httpdocs/mail/signup.php on line 132

Warning: Variable passed to each() is not an array or object in /home/httpd/vhosts/mailist.co.uk/httpdocs/mail/signup.php on line 134
ListMail Custom HTML not found! Please contact your administrator.

Should the new list number appear somewhere in the urlencoded vars to signup.php?
Cheers,
Paul

DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
Spaces in names creating problems in links
« Reply #5 on: March 18, 2007, 04:45:11 am »
Paul,

Yes, you're right.  Change this:
Code: [Select]
header('Location: '.$lmp.'signup.php?email='.urlencode($em).'&fname='.urlencode($fn).'&lname='.urlencode($ln));
To this:
Code: [Select]
header('Location: '.$lmp.'signup.php?email='.urlencode($em).'&fname='.urlencode($fn).'&lname='.urlencode($ln).'&list='.$list);
I have updated the original code for others.

Regards
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting

paulbeestonuk

  • Posts: 26
    • View Profile
Spaces in names creating problems in links
« Reply #6 on: March 19, 2007, 01:47:14 am »
Thanks Dean - it's working.
Paul.