denislexic
denislexic

Reputation: 11382

Passing variables through GET for a file_get_contents - a different way

I have information stored in a session. But was I just found out, sessions don't work when you do file_get_contents().

So after some searching I thought of using this technic:

$cart = base64_encode(serialize($_SESSION['cart']));

I pass my session cart, serialize it and encode it. I then pass it into the file_get_contents.

$url = "http://www.domain.com/pdf_order.php?cart=".$cart; 
$html = file_get_contents($url);

In the URL that it gets, I have this:

$cart = unserialize(base64_decode($_GET['cart']));

But I don't get anything. I can print out the GET cart and I have an encoded string, but then I can't do anything with it.

Any help, much appreciated.

UPDATE When I echo the URL I get this http://www.domain.com/pdf_order.php?cart=YTozOntzOjc6Imdhcm1lbnQiO2E6MTp7aTowO2E6Nzp7czo0OiJ0eXBlIjtzOjU6IlNoaXJ0IjtzOjY6ImFjY2VzcyI7czozOiJ5ZXMiO3M6MzoiaWREIjtpOjEwNDtzOjY6ImZhYnJpYyI7YToyOntzOjQ6InR5cGUiO2E6Mzp7czo4OiJkYl92YWx1ZSI7czo0OiJiZXN0IjtzOjExOiJwcmV0dHlfbmFtZSI7czoxNToiSSB3YW50IHRoZSBiZXN0IjtzOjM6InR4dCI7czoxNDY6IjEwMCUgQ290dG9uPGJyIC8+SWYgeW91IHdhbnQgdGhlIGJlc3QsIHdlJ2xsIGdpdmUgdGhlIGJlc3QuICBDb3R0b24gaXMgdGhlIG1vc3QgY29tZm9ydGFibGUgZmFicmljIGFuZCBpcyBhIGZhYnJpYyB0aGF0IGJyZWF0aHMuLi55b3UnbGwgZW5qb3kgaXQuIjt9czo1OiJwcmljZSI7aTo5MDt9czozOiJpZFMiO3M6MjoiNTIiO3M6OToicXR5X1NoaXJ0IjtzOjE6IjQiO3M6NDoicXR5XyI7czoxOiI0Ijt9fXM6MzoiaWRBIjtzOjg6IjExMTExMTUxIjtzOjExOiJhY2Nlc3NvcmllcyI7YTo0OntpOjA7YTo0OntzOjM6ImlkQSI7czoxOiIxIjtzOjQ6Im5hbWUiO3M6ODoiU2xpbSB0aWUiO3M6MzoicXR5IjtzOjE6IjQiO3M6NToicHJpY2UiO3M6NToiMjcuOTkiO31pOjE7YTo0OntzOjM6ImlkQSI7czoxOiIyIjtzOjQ6Im5hbWUiO3M6ODoiU2xpbSB0aWUiO3M6MzoicXR5IjtpOjE7czo1OiJwcmljZSI7czo1OiIyNy45OSI7fWk6MjthOjQ6e3M6MzoiaWRBIjtzOjE6IjMiO3M6NDoibmFtZSI7czo4OiJTbGltIHRpZSI7czozOiJxdHkiO2k6MTtzOjU6InByaWNlIjtzOjU6IjI3Ljk5Ijt9aTozO2E6NDp7czozOiJpZEEiO3M6MToiNCI7czo0OiJuYW1lIjtzOjg6IlNsaW0gdGllIjtzOjM6InF0eSI7aToxO3M6NToicHJpY2UiO3M6NToiMjcuOTkiO319fQ==

Upvotes: 2

Views: 11702

Answers (2)

James
James

Reputation: 5169

Check out How to post data in PHP using file_get_contents? it's pretty much doing what you want to do, by creating a stream.

I'm guessing you can still put $_SESSION variables in there too.

Upvotes: 1

Pandurang Zambare
Pandurang Zambare

Reputation: 94

If you are working on same server as www.domain.com then why do you need to use file_get_contents() to get some data or do some processing . Use direct calls.

Upvotes: 0

Related Questions