Jump to content

$_GET, $_POST and $_SESSION


Libertine

Recommended Posts

Hi,

 

I do not have a problem with specific code but rather code design/technique. I am not able to articulate the problem very well but here goes.

 

I am building a [mostly] object oriented PHP store as a personal project to improve my PHP skills. However I'm running into some problems concerning my sorting, pagination and filtering facilities. I've tried to use $_GET to store the following:

  • Page being viewed by the user
  • Category (e.g. fruit or vegetables)
  • Sort method (e.g price ascending, descending etc.)

 

When the user clicks on a link to another page for example, I must append the page number to the URL, something like "index.php?page=2" but the other $_GET parameters are lost unless I do something like:

 

<a href=\"index.php?cat=".$_GET['cat']."&sort=".$_GET['sort']."&page=".($this->pageNum+1)."\">Next-> </a>

 

This means whenever there is a link or form submission I must find a way to carry over all those parameters to ensure the page and category are remembered, otherwise the user is returned to page 1 and the main category. It's a mess and has become too confusing with the introduction of other pages.

 

Clearly, I'm doing it all wrong. $_GET parameters alone are not a good solution here, at least how I'm using them. So I ask of you, what's the correct way to store information such as page number, sorting method and category? Must I use $_SESSIONS and if so how? Thanks.

 

Link to comment
Share on other sites

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.