Jump to content

*SOLVED* using query string to save the state of an object from file to file


drkstr

Recommended Posts

Hello!

I apologize if my question might seem a bit basic. I am about a day and half into learning how to do all this web development stuff, so I am a newbie to the 10th power. Luckly, I do have a little bit of a background in programming so I am not completly lost. :)

Here is what I am trying to do:
I need to direct the user to another php script but keep the same sate of my "user" object.

Here is what I've tried: (psuedo code)
[code]$currentUser = new User(); 
# <snipped out irelevent code>
$query = urlencode( serialize($currentUser) );
header( "Location:index.php?user=$query" );[/code]

now it will forward to index.php just fine, and I see the serialized url version of my object in the title bar, but I'm not sure how to grab it from the url.

I've tried both $_GET['user'] and $_SERVER['QUERY_STRING'] to retrieve the data, but they return empty strings. I have not been able to find the answer in my PHP book, google, or in RFC 2616.  Part of the problem is I don't really know what to look for. Can any one point me in the right direction?

Thanks in advance!
...aaron
Link to comment
Share on other sites

Thanks for the quick reply!

It appears that it does. I'm not positave though since a serialized object is so cryptic. Here is the text in the url bar after the forward:
[code]http://localhost:18881/index.php?user=O%3A4%3A%22User%22%3A3%3A%7Bs%3A12%3A%22%00User%00myName%22%3Bs%3A5%3A%22admin%22%3Bs%3A12%3A%22%00User%00myPass%22%3Bs%3A34%3A%22%241%24CsiOMyoi%24Lad1yieZJohpdTwvGcdG0.%22%3Bs%3A19%3A%22%00User%00myLoginStatus%22%3Bb%3A1%3B%7D[/code]


**edit**
The reason why I mentioned the RFC earlier was because I thought it might be possible to modify the http header to make it think that a get request was sent. The book that I have been reading states that the $_GET['item'] array only works when a get request was submitted (which I am assuming why my string is Null when I try to access it).

Unfortunatly, the RFC was a little bit to technical for me  :-\
Does anyone know how to use the header function to make my php script think a get request was submitted? Or is there a better way to make this variable populate?

thanks!
Link to comment
Share on other sites

Sorry to double post.

I've been able to resolve the original problem by using the "session" functions to store the object in a temporary file. However, I would prefer to be able to pass the data though the url if it's even possible.

Thanks for your time!
...aaron
Link to comment
Share on other sites

  • 2 weeks later...
Solved.

Forgot to use urldecode($string) before using unserialize($decoded_string).

regards,
...drkstr

*edit*
but I'm not going to do it this way anyways. After learning a little bit more about PHP, I can see that $_SESSION variables is a much better way to go about it.
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.