English 中文(简体)
How to deal with question mark in url in php single entry website
原标题:

I m dealing with two question marks in a single entry website.

I m trying to use urlencode to handle it. The original URL:

 search.php?query= .quote_replace(addmarks($search_results[ did_you_mean ])). &search=1 

I want to use it in the single entry website:

 index.php?page= .urlencode( search?query= .quote_replace(addmarks($search_results[ did_you_mean ])). &search=1 )

It doesn t work, and I don t know if I must use urldecode and where I can use it also.

最佳回答

Why not just rewrite it to become

index.php?page=search&query=...

mod_rewrite will do this for you if you use the [QSA] (query string append) flag.

http://wiki.apache.org/httpd/RewriteQueryString

问题回答

$_SERVER[ QUERY_STRING ] will give you everything after the first "?" in a URL.

From here you can parse using "explode" or common sting functions.

Example:

http://xxx/info.php?test=1?test=2&test=3

$_SERVER[ QUERY_STRING ] =>test=1?test=2&test=3

list($localURL, $remoteURL) = explode("?", $_SERVER[ QUERY_STRING ]);

$localURL => test=1

$remoretURL => test=2&test=3

Hope this helps

I would suggest you to change the logic of the server code to handle simpler query form. This way it is probably going to lead you nowhere in very near future.

Use

index.php?page=search&query=...

as your query format but do not overwrite it with mod_rewrite to your first wanted format just to satisfy your current application logic, but handle it with some better logic on the server side. Write some ifs and thens, switches and cases ... but do not try to put the logic of the application into your URLs. It will make you really awkward URLs and soon you ll see that there is no lot of space in that layer to handle all the logic you will need. :)





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签