Jump to content

Sessions and cURL


Summthing

Recommended Posts

Ohai.

 

So, I'm trying to cURL all of the f2p items, and put them into a session. I've added all of the items so they look like $_SESSION['fur'] = ge_item(6814) (Thanks Peter :mrgreen: )

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

 

Thank you very much.

Link to comment
Share on other sites

Add

session_start();

Just under the <?php tag on every page you need the session data on.

[hide=Drops]

  • Dragon Axe x11
    Berserker Ring x9
    Warrior Ring x8
    Seercull
    Dragon Med
    Dragon Boots x4 - all less then 30 kc
    Godsword Shard (bandos)
    Granite Maul x 3

Solo only - doesn't include barrows[/hide][hide=Stats]

joe_da_studd.png[/hide]

Link to comment
Share on other sites

Indeed, make sure that session_start() is before anything is printed. That means that this will not work:

<!doctype html>
<head><title>Blah</title></head>
<html>
<body>
<?php
   session_start();
//Rest of your code here
?>
</body>
</html>

Because session_start() needs to send the headers, if headers are sent before it's called, you'll get an error (Headers already sent in file.php on line X).

 

This is how you'd do it:

 

<?php session_start(); ?>
<!doctype html>
<head><title>Blah</title></head>
<html>
<body>
<?php
//Rest of your code here
?>
</body>
</html>

C2b6gs7.png

Link to comment
Share on other sites

Okay, I've added that, but when I try

 

<?php
session_start();
echo $_SESSION['fur'];
?>

The page is blank. Any idea why?

 

I apologize for my ineptitude #-o

 

Make sure you set the session variable before echoing it. Try checking if it's set.

<?php
session_start();
if(isset($_SESSION['fur'])) {
   echo $_SESSION['fur'];
} else {
   echo "It's not set";
}
?>

Link to comment
Share on other sites

...why does it say that PureMageUK wrote this?

 

I wrote the functions gp_convert() and ge_item() (the latter of which he's modified) and he's using them with my permission.

 

I'd also like to point out that although I know you're new to PHP that:

  • This isn't the most efficient way to retrieve lots of items as curl_close() is called every time and then it has to be initiated again for the next item.
  • Caching could be used to greatly improve page load times since you won't be pulling from Jagex on every load.

 

Your issue should be sorted by including session_start(); like dsavi said. Ensure you're calling it in the page with the ge_item() calls as well. The session needs to be started for you to be able to assign session variables.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.