I use a index.php to control the access of pages.
Here is the mechanism:
Index.php redirects the page to search.php; code: index.php/?page=search
the path of search.php is : pages/search.php
, search.php includes header.html, body.html etc.
Now in body.html we call search.php using: index.php/?page=search
parameter, and body.html includes this code: index.php/?page=search?query='.quote_replace(addmarks($query)).
You can see there are two '?'. And it's just this problem.
When i browse search.php, it displays in url: example.com/?page=search
.
When i click the button in search.php while actually 开发者_开发问答in body.html, it displays in url example.com/index.php/?query=&search=1
.
In this way, the browse just display page index.php. But i want to display the search result in search.php, and it should display example.com/?page=search/?query=&search=1
. But you can see /?page=search
disappears and /index.php
appears here.
I'm sorry, the condition is complex and i don't describe it very well. If you couldn't understand it very well, i'll explain.
So, do you have any advice about that? Thanks a lot.
If you want to use a string (such as search/?query=&search=1
) as a URL argument, you need to encode so that it no longer contains special charachters such as ?
and &
. Use the urlencode() PHP function for this:
urlencode("search/?query=findme&search=1")
This will yield the following string, which can be safely included as a URL argument:
search%2F%3Fquery%3Dfindme%26search%3D1
To build the first string you need to so something similar, i.e. encode all arguments. Here the http_build_query() function can be useful, which takes an array with keys and values, encodes all of them and adds the =
and &
characters where needed:
http_build_query(array("query" => "find&me", "search" => "1"))
which yields
query=find%26me&search=1
精彩评论