Grabbing a $_GET variable from another website

Hey all, I’m just wondering if it’s possible to write a page in php (or any other way) that would be able to call or grab a $_GET variable from another page and use it in the original page.

So, let’s say I go to www.example1.com and the $_GET variable it passes in the url is ?var=123, and the value of that variable changes every day at random.

Now I’ve got my own site on www.example2.com and I want to be able to make links on it to example1.com that will, when it loads, check example1.com to see what the current value of $var is at example1.com and plug that in to my links on example2.com

I know I can just create my own $_GET variable and plug it in to the address bar, just wondering if there’s a way to automate the process.

Thanks for your time,

Hello,

do you own both websites?

No, the site in question is an online game site I play on. I want to make my own portal with an html frame so I can combine frequently done tasks into easy to access direct links instead of having to drill down 3 links to access each of them.

well there you go, you can use an iframe to display the partial data you need from that website.

another approach could be done by retrieving only partial part html that you need and then just display it on your website

Thanks. I’m not one of those new users who asks helpers to do everything for me, but could you hook me up with a tutorial or a search term I could put in to google to teach myself how to do what you’re suggesting?

before i lead you anywhere, can you show me an example of exactly what you want so i can can have mental picture.

Sure. There’s an online game I play. I won’t say which so that I’m not spamming but let’s call it gamerville.com

All the game play is down through your web browser, so you click on battles and then click on the other player you want to fight or whatever.

As with any game you can build up your stats. So lets call one of these stats Experience.

So under normal circumstances, you click on Cave to access the cave section of the game, then cavern 1 for Experience training, then you click the Train! link.

So really if I want to train Experience I have to click 3 links. I’d like to be able to create a link on my site directly to the Train! link, but the problem is this variable in the url keeps changing. And if it doesn’t match it doesn’t work. I’ve tried setting it at as a bookmark but it breaks the next day when the variable changes.

so, I’d like my site to be able to capture the variable in the url www.gamerville.com?var=123 and then plug it in to my links like so.

[php]<?php

$var = CAPTUREDVARIABLEFROMGAMERVILLE.COMURL

echo ‘Train!’;

?>[/php]

I don’t think is possible, because the code that you need is regenerated on every visit right?
therefore we would need a script that go to the URL and gets the URL so then you can take that special code out using php substr function.

however i will do some research and post back if i find anything.

and hopefully other php buddies will drop by and help.

Its sounds like a aspx site that generates a key each time you visit but this could could be also done in php.
Without looking at the site would be hard to say.
You could try scraping the data from the site with curl, so curl would click the links for you then you open up the page from the link your left with.

Thanks for the help guys. I figured it out using curl, and some example scripts posted online. I found the original script here and modified it to suit my needs.

Here’s a dummy copy of the script in case anyone ever needs help with the same question.

[php]<?php

//The site you want to login to.
$login_url = ‘http://www.testsite.com/login/’;

/*
To get this info go to the site you want to login to and view the source, look for
name=" to find out what each value is called, to learn more check out HTML form posting.
*/
$post_data = ‘login=PUTYOURLOGINNAMEHERE&password=PUTYOURPASSWORDHERE’;

//Create a curl object
$ch = curl_init();

//Set the useragent
$agent = $_SERVER[“HTTP_USER_AGENT”];
curl_setopt($ch, CURLOPT_USERAGENT, $agent);

//Set the URL
curl_setopt($ch, CURLOPT_URL, $login_url );

//This is a POST query
curl_setopt($ch, CURLOPT_POST, 1 );

//Set the post data
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

//We want the content after the query
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//Follow Location redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

/*
Set the cookie storing files
Cookie files are necessary since we are logging and session data needs to be saved
*/

curl_setopt($ch, CURLOPT_COOKIEJAR, ‘cookie.txt’);
curl_setopt($ch, CURLOPT_COOKIEFILE, ‘cookie.txt’);

//Execute the action to login
$postResult = curl_exec($ch);

/*
What this part does is it searches the post login page for the term ?value=, returns
what character it is in the string, adds 7 (the length of ?value=) and delivers the next
3 characters (the part I’m looking for) into $value
*/
$value = substr($postResult, (strpos($postResult, ‘?value=’) + 7), 3);

?>[/php]

Good to know thanks

Sponsor our Newsletter | Privacy Policy | Terms of Service