Jump to content


Photo

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


  • Please log in to reply
4 replies to this topic

#1 drkstr

drkstr
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationSeattle, WA - USA

Posted 12 August 2006 - 10:42 PM

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)
$currentUser = new User();  
# <snipped out irelevent code>
$query = urlencode( serialize($currentUser) );
header( "Location:index.php?user=$query" );

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

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 12 August 2006 - 10:57 PM

when this goes to a new page
does the index.php
have the full information in the url
www.example.com/index.php?user=onlyican
For example
Tell me the problem, I will try tell you the solution

#3 drkstr

drkstr
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationSeattle, WA - USA

Posted 12 August 2006 - 11:03 PM

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:
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


**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!

#4 drkstr

drkstr
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationSeattle, WA - USA

Posted 13 August 2006 - 12:46 AM

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

#5 drkstr

drkstr
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationSeattle, WA - USA

Posted 25 August 2006 - 03:54 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users