Jump to content

url reconstruction with php


Ninjakreborn

Recommended Posts

Any site that carries a lot of information you notice you use a lot of state saving.  Sessions, cookies, get, post, all over the place.  The site I am doing, uses a lot of sessions, it uses a lot of posts, and alot of get's
It comes down to certain areas, where I am chaining together a good number of variables.
http://www.domainname.com/display.php?school=UPenn&category=Item&subcategory=Sporting%20Goods&postset=postset1

and at some points it might get even bigger, is this going to present a problem, I heard when it get's over 255 characters, then there's a problem, because some browsers can cut some of that off.
That's under 100 all together, with all characters together including hte domain name, so I know this should be fine, but in the event, I get it 2-3 times longer than that(hasn't happened yet), what can I do, to prevent this, or what do I have to worry about with doing it like that.
Link to comment
Share on other sites

Also dont use words as your variables. Shorten them such as:
sch for school
cat for category
scat for subcategory
ps for post set.

No need to make your variables so obvious to the user what they are. That you can do in your actuall code using comments. Additionally you might want to use mod_rewrite to tidy up your urls so its like this:
site.com/schoolName/Category/subCategory/PostSet

Or just use SA's suggesstion and use another method. Such as use a temporary session variables which holds an array of School name, category, sub cat etc, Eg:
[code=php:0]$_SESSION['school_nav'] = array('sname' => 'SchoolNameHere', 'cat' => 'categoryName' ..etc..);[/code]

Then use $_SESSION['school_nav']['sname'] to access the school name
$_SESSION['school_nav']['cat'] to access the category etc.

Use the power of arrays when dealling with masses of data dont create 1 session var for each variable. Use arrays to store multiple things in an session which relate to each other.
Link to comment
Share on other sites

Whether I use that right now or not, I am not sure, but the advice you gave me may prove invaluable.  So I always have a group of sessions for the user, so instead, I can create an array. like
$_SESSION['userinfo'] = array(
then create a inside the array for there username, email, ip address, last logged in date, and everything else.  Then if I have admin later I could do
$_SESSION['admin'] = array
then have all that in there
then use temporary set's of session data for other things.
So tehre would actually never be a need for get if this was true, so there has to be negatives to doing that, what negatives come with doing that, that you know of? if any.
I like that idea
Link to comment
Share on other sites

There are uses for 'get', such as passing information from external sources. For example, if you send an activation email to someone requesting that they activate their account by clicking the link mysite.com/activate.php?id=546564

As far as I see it, there are no negative effects to using Wildteen's method, I use that method in my projects - Why pass data through the URL when you don't need too? It's both messy, and provides a small insight as to how parts of your system work.
Link to comment
Share on other sites

[quote author=businessman332211 link=topic=108662.msg437381#msg437381 date=1158687271]
Whether I use that right now or not, I am not sure, but the advice you gave me may prove invaluable.  So I always have a group of sessions for the user, so instead, I can create an array. like
$_SESSION['userinfo'] = array(
then create a inside the array for there username, email, ip address, last logged in date, and everything else.  Then if I have admin later I could do
$_SESSION['admin'] = array
then have all that in there
then use temporary set's of session data for other things.
So tehre would actually never be a need for get if this was true, so there has to be negatives to doing that, what negatives come with doing that, that you know of? if any.
I like that idea
[/quote]
Nothing as far as I know of. Its still the same thing just that you are using an array.
Link to comment
Share on other sites

I see what you mean, for now I used get, like wildteen said about cutting down the variable names. but now that I know this about sessions, I am going to start using little packets of information, as session arrays. I am goign to start passing information around that way, I am always afraid to use sessions, because I am afraid there might be something that won't work right, or something.  So I am going to put some thought into it, and start using that in my future projects, and see how the outcomes turn out.
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.