Jump to content

cURL and Sessions


Bonkerz

Recommended Posts

Ohai.

 

So, I'm trying to cURL a bunch of things off of a page, and put them into a session. I've added all of the items so they look like $_SESSION['fur'] = ge_item(6814)

Now I just need to figure out how to use them so that I can just echo $_SESSION['fur'] on any page so that it outputs what it's supposed to be (78)?

 

This is what I have so far:

http://pastebin.com/m6ef72a5b

 

Thanks,

Bonk

 

PS I apologize in advance for my ineptitude :shrug:

Link to comment
https://forums.phpfreaks.com/topic/192589-curl-and-sessions/
Share on other sites

As long as the function returns the correct value then on any page you want to use the session var.

 

You also  need to start a session at the top of the page that has your functions unless you are including it into a page that already has a session started.

 

session_start();
echo $_SESSION['var'];

 

 

HTH

Teamtomic

Link to comment
https://forums.phpfreaks.com/topic/192589-curl-and-sessions/#findComment-1014657
Share on other sites

I was confused about this at first as well.  The session_start() function is somewhat of a misnomer.  It basically tells PHP to retrieve a cookie from the client with the session ID.  If no such cookie exists (i.e this is the first page they hit with session_start() at the top) then it creates one.  Otherwise it just uses the existing cookie that it found.

 

So let's say you have two pages, one.php and two.php.  In one.php you could do something like this:

 

<?php
session_start();

$_SESSION['foo'] = 5;

echo "<html>";
echo "<body>";
echo "<a href=\"two.php\">click here to go to page 2</a>";
echo "</html>";
echo "</body>";
?>

 

 

 

This will generate a cookie for the client.  Then in two.php you call session_start() which will retrieve the cookie generated previously, so it's actually continuing the session.  Try this:

 

<?php
session_start();

echo "<html>";
echo "<body>";
echo $_SESSION['foo'];
echo "</body>";
echo "</html>";
?>

 

 

Try it out -- open your browser and go to one.php and then click on the link.  It will print 5.  You can also store the value of the session variable into another variable like:

 

$myVariable = $_SESSION['foo'];

 

 

It's really that easy!

Link to comment
https://forums.phpfreaks.com/topic/192589-curl-and-sessions/#findComment-1014667
Share on other sites

That works, but my stuff is a little more complicated than that and I;m stumped.  With the code that I pasted before, why can't I do:

 

<?php

session_start();

echo $_SESSION['half_anchovy_pizza'];

?>

 

It returns blank.

the variable in it should be ge_item(2299).

 

Confused.

Link to comment
https://forums.phpfreaks.com/topic/192589-curl-and-sessions/#findComment-1014675
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.