Welcome Guest, Not a member yet? Register   Sign In
URLENCODE doesn't work
#1

[eluser]Ludatha[/eluser]
For some reason urlencode doesn't work with my codeigniter, a have a script that encodes titles of forum threads so they can be used in the URL, but urlencode is not encoding :O

http://ludatha.com/forum/category/Spam Land.html

If you go to that website and click one of the threads that have special characters in them, it will say 404 not found, or Disallowed Key Characters...

The function urlencode does work on my server as I made a test script to test it
http://ludatha.com/test/testencode.php
It encodes fine

So here comes my code

Function:createURI
Code:
function createURI($id, $string, $place, $total = TRUE){
        $string = str_replace(' ', '_', $string);
        /*
        $string = str_replace('!', '', $string);
        $string = str_replace('?', '', $string);
        $string = str_replace(':', '', $string);
        $string = str_replace(']', '', $string);
        $string = str_replace('[', '', $string);
        $string = str_replace('"', '', $string);
        $string = str_replace('£', '', $string);
        $string = str_replace('$', '', $string);
        $string = str_replace('%', '', $string);
        $string = str_replace('^', '', $string);
        $string = str_replace('&', '', $string);
        $string = str_replace('*', '', $string);
        $string = str_replace('(', '', $string);
        $string = str_replace(')', '', $string);
        $string = str_replace('-', '', $string);
        $string = str_replace('#', '', $string);
        $string = str_replace('~', '', $string);
        $string = str_replace(';', '', $string);
        $string = str_replace('\'', '', $string);
        $string = str_replace('/', '', $string);
        */
        $string = urlencode($string);
        
        if($place == 'forum'){
            $url = 'forum/post/';
        }elseif($place == 'portal'){
            $url = 'portal/view/';
        }elseif($place == 'arcade'){
        $url = 'arcade/play/';
        }else{
            $url = '';
        }
        
        if($total){
            return base_url() .$url . $id . '-' . $string . '.html';
        }else{
            return $id . '-' . $string;
        }
    }

This is the code used to get the latest thread
Code:
$latestThread = $latestPostRow->name;
                        $latestThread = $this->db->escape_str($latestThread);
                        $url = $this->ludatha->createURI($latestPostRow->id, $latestThread, 'forum');
                        $lastPostContent = 'Last thread by <a >owner.'.html">'.$latestPostRow->owner.'</a><br />
                          in <a href="'.$url.'">'.$latestPostRow->name.'</a><br />
                          at '.$latestPostRow->postDate;

Can anyone help?
#2

[eluser]BrianDHall[/eluser]
I suspect the problem is str_replace - comment out the other code and immediately after using the replace, var_dump the $string. Then var_dump again after url-encoding and this should shed some light on what in sweet hell is going on in there.
#3

[eluser]Ludatha[/eluser]
[quote author="BrianDHall" date="1253949491"]I suspect the problem is str_replace - comment out the other code and immediately after using the replace, var_dump the $string. Then var_dump again after url-encoding and this should shed some light on what in sweet hell is going on in there.[/quote]

I tried that, and the outcome I got was actually url encoded... I don't understand...
I viewed the source of the page and the URL was actually
<a href="http://ludatha.com/forum/post/97-!">
(EDIT: there was a load of encoded characters here, but this forum has removed them all...)

But when I click on it the url changes back to the original, so I get the uri disallowed characters error.

Also when I hover over the link, the status bar shows the original link...

Can anyone help me?




Theme © iAndrew 2016 - Forum software by © MyBB