Welcome Guest, Not a member yet? Register   Sign In
URL help
#1

[eluser]DanielJay[/eluser]
I am working on creating an application that allows me to store my bookmarks in a database instead of in firefox as I use multiple computers. I have seen how the del.icio.us bookmark code works by making the bookmark url javascript as shown below:
Code:
[removed]location.href='http://del.icio.us/post?v=4;url='+encodeURIComponent(location.href)+';title='+encodeURIComponent(document.title)
so my bookmark url is:
Code:
[removed]location.href='http://[mydomain]/Portal/bookmark/addbookmark/'+encodeURIComponent(location.href)+'/'+encodeURIComponent(document.title)


However when I do make my link point to: http://[mydomain]/Portal/bookmarks/addbookmark/http://www.google.com/ I cannot pass this and it produces an apache 404. Portal is the root of CodeIgniter with my index.php, bookmarks is the controller and addbookmark is a function in the bookmarks controller.

If I create a really basic php page with the following and save this outside of my Portal directory. Then modify the bookmark url to http://[mydomain]/addbookmark.php?url=http://www.google.com/ everything works fine.
Code:
<?php
foreach($_GET as $key=>$value) {
echo $key.' = '.$value.'<br />';
}
?&gt;

I have even removed my .htaccess file trying to figure this out and it still produces an apache 404 when going to http://[mydomain]/Portal/bookmarks/addbookmark/http&#x3A;&#x2F;&#x2F;www.google.com&#x2F; .

Any suggestions?
#2

[eluser]alexsancho[/eluser]
maybe ci is taking the encoded slashes as real ones? you can try some kind of routing to check if this is the problem.

Code:
$route['bookmark/addbookmark/:any'] = "bookmark/addbookmark/$1";

just my two cents
#3

[eluser]DanielJay[/eluser]
I added this to my routes.php config file and this still does not fix things.

I have found that any time I put a urlencoded / in the URL it errors out. So the URL below would not work:
Code:
http://[my domain]/Portal/bookmarks/addbookmark/http&#x3A;&#x2F;&#x2F;www.google.com&#x2F;

Any other ideas?

Edit: It appears that the forums here are modifying my URL. The code that should be after the addbookmark/http should be: % 3A% 2F% 2F (Without the spaces between the % and the numbers)
#4

[eluser]Pascal Kriete[/eluser]
The problem is caused by the escaped slashes. Using escape() or encodeURI() works, but then you're left with the slashes - meaning segment(3) will simply be "http:".

The best solution I can come up with is to replace the slashes with something that most urls don't have, such as:
Code:
location.href='http://localhost/test/addbookmark/'+location.href.replace(/\//g, "__myseperator__");

That will replace all the '/' with '__myseperator__'.

Then in your controller you could replace them again to reassemble your link:
Code:
$encoded_url = $this->uri->segment(3);
$url = str_replace('__myseperator', '/');

There is probably a prettier way, but this works (as long as none of your bookmarks have __myseperator__ in them Wink).
#5

[eluser]bobqphp[/eluser]
hi, I've come across the same problem. I thought about the method described above, but what about other characters allowed in urls that CI doesn't allow (at least by default) in it's own urls? or do I change the "permitted_uri_chars" config option to include all characters allowed by urls?

I also thought about enabling query strings, but the warning message implies it might break everything else, and this being a web framework and all I was hoping I wouldn't have to mess with the internals like that...
#6

[eluser]Nathan Pitman (Nine Four)[/eluser]
I've come up against this today also. I'm trying to pass a URL encoded string which in some cases might include a forward slash. The encoded version of that causes CI to 404 on me, yet encoded @ signs work fine. Is there a pattern or at least a list of which characters CI will bork at?

'inparo'; your suggestion sounds like a good solution to my particular problem, for now at least. Thanks. Smile
#7

[eluser]Pascal Kriete[/eluser]
Glad it works for you Smile .

There is a list of permitted characters, called permitted_uri_chars, in config/config.php. Interestingly, I can't reproduce the forward slash error today. Do you have a sample url?

Also, there may be an easier way. Since the user needs to have javascript enabled for any of this to work, we can assume that we have access the url hash. So we could just add it there. On our site we then grab that and post it to the backend. No encoding needed.

Code:
// Link
http://[mydomain]/bookmark/addbookmark/#'+location.href

// addbookmark page
var url = window .location .hash.substring(1);
new Ajax.PostRequest('whatever you use');
#8

[eluser]Nathan Pitman (Nine Four)[/eluser]
To be specific, the scenario I have is that I'm be passed a urlencoded string from antoher script on another domain, when this included a URL encoded '/' CI 404'd on me. I don't have an example URL to link to as it's a live system and I've now fixed the problem and not keen on 'un-fixing' it! Smile
#9

[eluser]Pascal Kriete[/eluser]
Smile as long as it works.




Theme © iAndrew 2016 - Forum software by © MyBB