Jump to content

Recommended Posts

I'm very new to php, and I'm trying to keep ampersands from changing from & to &

 

I have a url that contains multiple ampersands. I'm trying to hand this variable off to an API line for a local url shortener script. However, the url shortener isn't working, and when I check what it has put into the mysql database, it's saving the url with & instead of &.

 

The page after submitting the form contains ampersands. On that page is the link for the same page, but being processed by the url shortener. This is the link that is wrong.

 

I've echo'ed out my variable I'm handing the API and the echo shows ampersands, and I've even checked the source of the html page where the echo is being displayed, and even in the source code, it shows ampersands not &

 

But when I check the db, the insertion for that short url page, has the page under the correct long url, but all ampersands are switched to &

 

Do I need to do something more with my variable before handing it to the API?

Do I need to contact the url shortner programmer?

Is there something I can search for in the url shortener script, to keep it from "cleaning" my urls I hand it?

Could this be some server setting that is causing this issue?

 

Any help on this problem would be greatly appreciated, thanks.

Link to comment
https://forums.phpfreaks.com/topic/301313-prevent-ampersands-from-changing/
Share on other sites

Without the exact code, it's hard to tell what's wrong. Is the URL shortener script publicly available?

 

HTML entities like & in the wrong places are often caused by poorly written code which blindly applies htmlspecialchars() or htmlentities() to all input “to make it secure”. That's what you could search for. Besides that, we can only speculate.

 

By the way, your own code should apply HTML-escaping to the URL before it's printed so that ampersands appear as & in the HTML source. Otherwise you may run into syntax conflicts or even security vulnerabilities.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.