url encoded forward slashes breaking my codeigniter app

后端 未结 4 1618
借酒劲吻你
借酒劲吻你 2020-12-06 01:34

i’m trying to create a url string that works like this:

/app/process/example.com/index.html

so in other words,

/app/process         


        
4条回答
  •  余生分开走
    2020-12-06 02:01

    One way to get around this problem would be to replace any forward slashes in your URL variable which you are passing in the URI segments with something that would not break the CodeIgniter URI parser. For example:

    
    $uri = 'example.com/index.html';
    $pattern = '"/"';
    $new_uri = preg_replace($pattern, '_', $uri);
    

    This will replace all of your forward slashes with underscores. I'm sure it is similar to what you are doing to encode your forward slashes. Then when retrieving the value on the other page simply use something like the following:

    
    $pattern = '/_/';
    $old_uri = preg_replace($pattern, '/', $new_uri);
    

    Which will replace all the underscores with forward slashes to get your old URI back. Of course, you'll want to make sure whatever character you use (underscore in this case) will not be present in any of the possible URIs you'll be passing (so you probably won't want to use underscore at all).

提交回复
热议问题