Jump to content

Best method to pass data via url?


Re321

Recommended Posts

hello,

 

I have an image generator basically, to create an image based on data. what I need to do is parse roughly 12 entries (not too long) and generate an image out of them.

 

since it's an image I need to send it to another php form through $_GET data (as <img> uses an external resource, I can't pass it through $_POST) but im not sure what is the best way.

 

urlencode I think works, but it may be too long for the GET url, what do you think is the best method?

  - urlencode

  - base64_encode

  - serialize

  -...

 

just to encode the 12 (5-30 in length each) POST entries so I can use them, I just am  not sure what is a good solution to pass those values to the other php page o_O;

Thanks

Link to comment
https://forums.phpfreaks.com/topic/199208-best-method-to-pass-data-via-url/
Share on other sites

if urlencode works, then use that.  base64_encode() and serialize are just ways of masking values (not their real use, but in this case, that's all they'd be doing really), so using them is not going to change anything, execpt make the string longer.

 

however, you shouldn't worry about the length of a URL as modern day browsers are capable of accepting thousands of characters/bytes in a URL string.

 

EDIT:  are the entries in an array?  i'm not following that aspect of the equation.

if urlencode works, then use that.  base64_encode() and serialize are just ways of masking values (not their real use, but in this case, that's all they'd be doing really), so using them is not going to change anything, execpt make the string longer.

 

however, you shouldn't worry about the length of a URL as modern day browsers are capable of accepting thousands of characters/bytes in a URL string.

 

EDIT:  are the entries in an array?  i'm not following that aspect of the equation.

 

Sorry. I am passing the $_POST array completely, the $_POST array has roughly 12 indexes which are 5-30 characters or so, since I need to pass it through url I was wondering what method produced the shortest string to pass through $_GET. (like generator.php?data= (the data))

Sorry for the confusion! I tested 4-5 things..  In case anyone is wondering,

 

With 14 POST entries the same length:

  json_encode on $_POST was roughly 182 characters

  url_encode on json_encode was ~300 characters

  serialize on $_POST was roughly 280 characters

 

  base64_encode on serialize was ~320 characters

  base64_encode on json_encode ~ 244 characters

 

So B64 on json_encode will work best for the $_GET url for me, no url encoding and it solves my problem. ^_^

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.