Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Best way to send hundreds of variables from page to page without taxing the server in PHP (or JavaScript)?

Featured Replies

I'm working on a website that uses over 200 variables that need to be sent from page to page. Each variable holds a small amount of data. The largest is probably a text string of around 200 characters. I use WordPress for part of the site but not all of it, so the variables need to be sent to WordPress at some point. I already have it working in PHP but I use a MySql database to store the variables. The variables change often, so there are queries happening often. Apparently this would not work well if the site had many users.

So my question is, what would be the best way to store and transfer over 200 variables from page to page on a website without it being too taxing on a server? I'm using PHP but could possibly use JavaScript.

I'm assuming JavaScript localStorage would be the best option, since the variables would be stored locally, but it would be hard for me to convert my site to pure JavaScript. I tried it yesterday and got quite far but some aspects were tricky for me, since I am only a hobby coder. I could do it if it was essential but I'd rather use PHP if I could. It would set me back a while.

Other options I'm aware of are SESSION variables and POST variables. Out of the two I'm assuming POST variables would be better. Would over 200 POST variables be taxing on the server if there were many users online?

Another option would be cookies, but I think I'd have to store lots of my variables in a few cookies not to exceed the cookie limit. Would this be feasible?

Any help would be greatly appreciated! Thanks!

Why 200? That seems like an awful lot.

Anyway, encoding might be the answer. Here are some examples:

https://stackoverflow.com/questions/13480491/encode-and-store-multiple-variables-in-url

But I’d really think about those 200 variables. Do you really need to pass all of them every time?

Also I wouldn’t worry about lots of DB queries. If you have decent hosting is can easily cope with thousands of people visiting the site.

 

  • Author

@fisicx Thanks for replying! Sorry I should have explained, the site allows users to customize photo greetings cards, much like moonpig. The variables store the positions and sizes of the photos and text along with the content of the text. Some templates have 15 photos, so lots of variables needed. The user is unaware of all this of course, they just see the card template.

I might be able to trim a few variables here and there but most are needed. The only time all the variables are accessed is when the card template is first displayed. Then it's only the variables associated with whatever element is being edited. The database is accessed every time the user changes something, such as uploads a photo or edits the text, and also when the user navigates to another page, such as the inner part of the card. I was thinking it would be better if these changes were stored some other way and then if the user purchases a card the data could be stored in the database only at the end. Or is the way I've already done it OK?

You said you're using PHP and MySQL, could you not have a table to store these customisations /settings/variables in as JSON, perhaps with an UUID as the PK, a text or json column type for the settings, and a created_at and updated_at timestamps.

That way you can just keep the UUID in the users session, and then in PHP you can get the settings out of the table, run them through json_decode() and you've got all your settings to use server side and pass to the view layer for the customer.

You could then have a task running on the server regularly to delete settings that are older than X hours to keep the table size low and also avoid storing data any longer than you need to.

  • Author

@jpeters8889

Thanks for replying. I like the sound of your idea. It sounds similar to what I already have but perhaps taking up less space. At the moment I have a table with a row for each individual variable, such as pic1_left, pic1_top, pic1_width, text1_font etc. And I allocate a row with a unique identifier number in a separate table to each user as they edit a card. Those rows get deleted after a day if the user hasn't purchased the card or placed it in the basket.

I've never used JSON files but it sounds like it would work well for what I need. My only questions would be, would each variable within the JSON file be easy to access and change? And would the benefits of switching to the JSON method be worth the work of changing what is already working well? I mean, would the way I have it working now cause enough performance issues to justify the switch?

  • 2 weeks later...
  • Author

Sorted!

I have now stored my 200+ MySql columns in one JSON MySql column, which is faster to access. These are transferred to client side localStorage when the page first loads and the page is then built in JavaScript. The user's uploaded photos are also stored client side in IndexedDB during customization and will then be transferred to the server if a purchase is made, along with the variables. So the customization process with all the variables and photos is all handled client side now. I'm assuming this is the best way to do it but of course I'll have to wait and see how it all works when on a live server.

  • Author

@fisicx Thanks! I'll post the url when live but I have a lot more work to do yet. At the moment I have just over 50 card templates designed. I guess I need to get that up to around 100+ before I can go live. Plus (a big plus!) I haven't actually got a printer yet! I'm still researching this. I don't actually know if there's a viable business in this but I'm hoping there is. My preliminary research seems to suggest there is, due to being able to charge a higher price for the personalized element of the cards.

In the meantime I can share a video of the site if you're interested. I'll update this thread when I have the video available.

  • Author

I'm guessing people want personalized cards since moonpig and funkypigeon are very successful businesses. The owner of moonpig was a dragon on Dragon's Den.

I'm not sure what Canva is or how it can do the same as what I'm going to offer? I'm assuming my site will be much easier to use than Canva for personalizing cards and sending them to the customer? Perhaps Canva would be better suited to people who don't mind spending more time on the design, whereas mine will be better suited to people who just want to click on photos and upload them quickly without having to think about the design at all.

You may well be right. 
 

Your biggest issue is not going to be the app. It’s marketing. When the likes of moon pig are spending millions on marketing (including TV ads) how are you going to compete? You might have some niche success with some targeted advertising but the likelyhood is people will gravitate back to trusted brands.

What’s your USP? Why would someone buy from you and not the national brands or local suppliers? A printer near us offers exactly this service.

  • Author

Well yes, assuming I can find a printer that can produce a quality card without having to wait 10 minutes, the only thing stopping it from being a success would be marketing. I have a bit put aside for marketing but it's insignificant compared to funky pigeon. One thing on my side though is the fact I can produce motion graphics myself, so I can make an ad but I'll have to pay to get it seen.

Another thing I can do is charge less than funky pigeon. Last time I checked they charge £5.99 plus £1.45 for postage, so that's £7.99 for an A4 card. I could charge at least one pound less than that and still make a decent profit, though I won't know for sure until I get exact figures.

I've also thought about how I can offer a genuine USP but I haven't got the definitive answer yet.  I've had a few general ideas.

About local printers, I had a card printed out from Max Spielmann and the quality was really bad. Even their logo on the back of the card was really poor quality, and they charged £5.99 for it. They have a cheek charging that. I'm not sure if they offer an online service. If they don't you'd have to take your photos to them on a device, which is not always ideal.

Most small businesses are competing with the big names. There seems to be hundreds of people selling posters and prints on eBay, a service which big companies offer. The amount of companies offering personalized greetings cards is relatively small compared to other print services, probably because it's expensive to get a website that can do that. If I can get a small piece of that pie there's a small chance it could work. But even if it doesn't it's been a great project to work on and it's helped me through a tough time personally.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.