473,706 Members | 2,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing & in url variable

pradeepjain
563 Contributor
hi,
I need to pass a variable like alias='F&B' in url. but when i try to get the value in next page using $_GET ,its breaking.

url like

Expand|Select|Wrap|Line Numbers
  1. http://example.com?alias=F&B
how do i pass it as entire data and get it in next page?
Mar 17 '10 #1
11 5502
Atli
5,058 Recognized Expert Expert
Hey.

The & character has special meaning in the query string of an URL. You need to urlencode() it before adding it.

If you can't do it via PHP, the URL encoded replacement for "&" is "%26".
Mar 17 '10 #2
pradeepjain
563 Contributor
i have done that.i use ralurlencode
and the url looks like

Expand|Select|Wrap|Line Numbers
  1. http://example.com/Restaurants?aliasF%26B
but when i try to print like

Expand|Select|Wrap|Line Numbers
  1. $alias =  rawurldecode($_GET['alias']);
  2. echo $alias;
its prints only F. how to solve it?
Mar 17 '10 #3
Atli
5,058 Recognized Expert Expert
You forgot the = in the URL, between the key and the value.

And you don't need the rawurldecode() call. The query-string is decoded automatically.
Mar 17 '10 #4
pradeepjain
563 Contributor
hey the = i forgot while typing . but still its not working.
Mar 18 '10 #5
pradeepjain
563 Contributor
hey i have few things to explain over here . basically i have .htaccess entry like

Expand|Select|Wrap|Line Numbers
  1.  RewriteRule ^Restaurants/(.*)$ /restaurant_rating.php?alias=$1 [L]

so i pass like
Expand|Select|Wrap|Line Numbers
  1. http://abc.com/Restaurants/F%26B  
which gets converted to

Expand|Select|Wrap|Line Numbers
  1. http://abc.com/restaurant_rating.php?alias=F%26B
internally .

so when i tried directly to use
Expand|Select|Wrap|Line Numbers
  1. http://abc.com/restaurant_rating.php?alias=F%26B
and print alias . it prints properly but when i use

Expand|Select|Wrap|Line Numbers
  1. http://abc.com/Restaurants/F%26B  
and print alias it prints only F .how to solve this problem ?
Mar 18 '10 #6
Atli
5,058 Recognized Expert Expert
Ok, I see.

The problem here seems to be that by using a mod_rewrite re-route, you are essentially making two requests. - mod_rewrite internally re-directs you from the original URL to the re-written version.

So when you start out like this:
- http://example.com/Restaurants/F%26B
Apache takes the original URL and translates %26 to & (as per usual), and then hands it over to mod_rewrite, which re-writes the URL and redirects you, using & instead of %26.
- http://example.com/restaurant_rating.php?alias=F&B
Which again, makes the URL invalid (the & being read as a variable seperator, rather than a part of the value.)

What you need to do to overcome this, is to manipulate the original URL so that when it is re-written by mod_rewrite, the outcome of the redirect is a valid URL. - To that end, you can encode the % in the %26 value, so when it is rewritten it becomes just a normal %.
- http://example.com/Restaurants/F%2526B
Which is translated to
- http://example.com/restaurant_rating.php?alias=F%26B
From which PHP can extract "F&B".


P.S.
Also take into account, that if mod_rewrite does multiple re-writes (chain rewrites), then each of them would need to be accounted for.

... You may well be better of either using an ID rather than a name, or restrict names to non-special characters.
Mar 18 '10 #7
Atli
5,058 Recognized Expert Expert
It seems that a workaround for this problem exists in Apache 2.2. (See mod_rewrite - Apache HTTP server.)

If you add the "B" flag to the rewrite, mod_rewrite will escape special chars for you.
Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^(.*)$ index.php?show=$1 [L,B]
Mar 18 '10 #8
pradeepjain
563 Contributor
i tused the option B like u said .


Expand|Select|Wrap|Line Numbers
  1.  RewriteRule ^(.*)$ index.php?show=$1 [L,B]
but apache is throwing internal server error
Mar 19 '10 #9
Atli
5,058 Recognized Expert Expert
Which version of Apache are you using? Like I said, this only works with Apache 2.2. If you are using an earlier version, you can't use that. You will need to double-escape instead. (Or just upgrade your server.)

In any case, check the Apache error logs and see what the problem is, exactly.
The Error log is usually located under: "logs\error.log " in your Apache install directory, or under: "/var/log/apache/" on Linux. (Can vary based on the type of install you used.)
Mar 19 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
8755
by: jbatty | last post by:
I am trying to display an image on my page by using "img src= hyperlink". the hyperlink is stored in a c# variable. but i seem to have the syntax mixed up. This passing the image directly works e.g. objCell.Text = "<img src=\"image.gif\">"; but using a variable does not seen to work. String imageLocation="image.gif";
1
1742
by: Vikram | last post by:
i am adding a row in dataset , in which i want to add &nbsp; (space chracter for html) and then want to bind dataset to asp.net dropdown list box. But & automatically converted to &amp chracter. Is there any way by which &nbsp; can be retained as it is when dropdown throws the html part. THanks
0
1202
by: CES | last post by:
All, I was wondering is their a way of passing a variable into an eval() statement? I've created a custom eval() dll to use with my VB.net code. Every thing works fine until I try to pass a variable into the text string . In the code below I'm trying to pass the variable zz into txtFS which comes from the file file.txt. Any suggestions on how to get this to work would be appreciated. CES
6
1505
by: brian_harris | last post by:
I have a function that passes a string class pointer to a function, this function is then suppose to fill it and the outer function uses it. But I believe that I am running into problem due to manged memory. Because it has value in inner function, but does not have the assigned value in outher function. So I need to know how to declare this variable and make assignments correctly so that it will have value when it is back in outher...
1
3268
by: Shawn | last post by:
As if it won't be clear enough from my code, I'm pretty new to C programming. This code is being compiled with an ANSI-C compatible compiler for a microcontroller. That part, I believe, will be irrelavent. My syntax is surely where I am going wrong. I'd like to be able to call this routine to read different values from another device. This routine would be called quite simply as follows: void main() {
3
1984
by: James Robertson | last post by:
I am new to the ASP and VB thing so be kind. Question I have is that I have created an ASPX web site to use as an E-Mail page. But I want to use this for a lot of users. Can I create the link on the WEB site to mail to passing a variable from the WEB site to the ASPX web site to E-Mail to? Hope I explained this correctly. This is a response from another group. There was no way for you to know it, but this is a classic asp newsgroup....
1
1680
by: I.am.the.Buddha | last post by:
I am still learning asp and sql. I am having trouble with passing a variable to within an sql statement. I am sure it is something simple like misuse of quotes. Since it may help if i say what i am trying to generally accomplish here. This is an access database for products and customers. We have a counter for each product (such as ProdCountLB, ProdCountSH, etc for the field names in a table called ProdCount). This worked fine when i...
2
1967
satterfieldben
by: satterfieldben | last post by:
I have a newbie question about passing variables between functions. I am wanting to use a drop down box to select a value. Then base on which was selected, it would create a variable and I would call that variable in another Java script. Sample script <SCRIPT LANGUAGE="JavaScript"> function GetSelectedItem() { len = document.formname.selectname.length i = 0 chosen = "none"
6
1377
by: artev | last post by:
Parse error: syntax error, unexpected '=', expecting ')' on function so function pippo($var1, &$var2 = null, $var3 = null) { ....} but if remove & I not have the erros; I must change sometime in php.ini or can resolve how?
0
8773
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7897
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5935
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4705
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2495
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2084
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.