PHP Help. - ? in URLS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Simon Angell
Forum Commoner
Posts: 45
Joined: Fri Jan 24, 2003 12:14 am

PHP Help. - ? in URLS

Post by Simon Angell »

Hi All.
I am currently playing with sripts, and have come across a problem, that i
can't slove. (i am a novice - lol).
The script requires a URL to grab data from.
The URL in the script is
http://www.weatherzone.com.au/yourHomeP ... f2eeb571ed

The script uses the URL to see the page and store it locally, then another
script grabs selected data from that page. the stuff after the ? is
essential for the data i want to be displayed, with out that part, the
script only sees the base page without the data i need, so hence it doesn't
grab it.
Now i figure it has something to do with the ? in the URL but i can't
seem to fix it myself.

Thanks
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

isn't that a jsp script? :?


+ more detail, eg. source
Simon Angell
Forum Commoner
Posts: 45
Joined: Fri Jan 24, 2003 12:14 am

Post by Simon Angell »

the url im trying to grab data from is jsp the script is php.
this is the script.

<?php
//Writing of local file

$rContents = implode( "\r\n", file(
'http://www.weatherzone.com.au/yourHomeP ... f2eeb571ed' ) );

if( ($fp = fopen( 'wztest.txt', 'wb+' )) !== false )
{
fputs( $fp, $rContents );
fclose( $fp );
}
?>

notice after the ? in the url is ref=f2eeb571ed, the script grabs the url http://www.weatherzone.com.au/yourHomePage.jsp but not the stuff after the ?, the stuff after that is what gives me the data that i need to grab. Because the script only "sees" the stuff ebfore the ?, i don't get the data i need.
Simon Angell
Forum Commoner
Posts: 45
Joined: Fri Jan 24, 2003 12:14 am

Post by Simon Angell »

I Figured it was a simple thing, but obviosly not :(
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post by fractalvibes »

Not sure what you are trying to do....

But any URL you see that looks like
http://www.somesite.com/somepage.php?ID=3&MYTYPE=c

Is such that everything after the ? is something considered a querystring.
SO, in the example above - the ID and MYTYPE are variables sending values that the somepage.php script can use. Chances are that the
http://www.weatherzone.com.au/yourHomeP ... f2eeb571ed

REF=f2eeb571ed
variable used in that URL are used by youHomePage.jsp to build some
things dynamically into the page dependant upon that ref variable.

And chances are that you need to know this and perhaps generate that URL
dynamically yourself, building the value of the ref variable on the fly?

Phil J.
Simon Angell
Forum Commoner
Posts: 45
Joined: Fri Jan 24, 2003 12:14 am

Post by Simon Angell »

Yeah, the yourhomepage.jsp uses the ref# to generate content on the fly. what the script above is suppose to do is grab yourhomepage.jsp along with the data generated by the ref#, it then writes the file locally as a .txt file, outputting the HTML source code generated, i then have another script reading that file and grabbing data that i set for it to grab. i can (and will) skip the writing of the local file, and just use the script that grabs the .txt file to grab the URL directly, but i need to know what i must add into the script for it to reconise the ref# after the ?.
DeGauss
Forum Contributor
Posts: 105
Joined: Tue Oct 22, 2002 9:44 am
Location: Gainesville, FL

Post by DeGauss »

So let me get this straight...

You want this: grabPage.php?ref=f2eeb571ed to work?

I'm just trying to break your question down into a simpler question...
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

I assume that Simon is saying that if u have a page
http://www.somedomain.com/page.php?name=123
then what do you have in page.php to access the "123" associated with it

I use $name and it works for me just as i do for foms.
so you could reference the "123" by using $name and it contains whatever is associated with "name" in the url.

But it may be different with newer versions of php, cuz apparently u can't use $name for forms with the post method
so I dunno if you can do that for variables in newer versions of php?
DeGauss
Forum Contributor
Posts: 105
Joined: Tue Oct 22, 2002 9:44 am
Location: Gainesville, FL

Post by DeGauss »

Yeah, register_global_vars is turned off by default nowadays... But then i'm still not sure what Mr Angell is trying to achieve.

$_GET["blah"] would work with a url of blah.php?blah=blah

*shrug*
Simon Angell
Forum Commoner
Posts: 45
Joined: Fri Jan 24, 2003 12:14 am

Post by Simon Angell »

i thought i explained what i wanted to do before, but here it goes again, in point form.
  • The Script uses a remote URL to grab data from, in this case http://www.weatherzone.com.au/yourHomeP ... f2eeb571ed
    That URL uses JSP, ok. the ref=# after the JSP is required to dynamically build a webpage.
    The script does not "see" the ref=# and therefor the webpage built is just the basic JSP script.
    I need the ref=# to be seen for the script to grab the dynamically created webpage.
    why? because the dynamically created webpage contains data that i am going to use, without the ref=# the data is not generated.
    So how do i get the php script to see the ref=# in the url???
the $_GET has been mentioned to me before, but how do i use it in my script?
Last edited by Simon Angell on Tue Jan 28, 2003 8:08 am, edited 1 time in total.
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

protocol://domain.name/directory/file.name?variable1=something&stuff=somethingElse

echo $_GET['variable1'];
echo $_GET['stuff'];
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

I think I'm getting what Simon is saying...

What I can understand is that the file() function

Code: Select all

file('http://www.weatherzone.com.au/yourHomePage.jsp?ref=f2eeb571ed')
would only use the filename part and not the query string.

I do think that file() doesn't forward the ?ref= part... So in effect it uses http://www.weatherzone.com.au/yourHomePage.jsp for the URL...

Simon if you have PHP 4.3+ did you try file_get_content() ? http://www.php.net/manual/en/function.f ... ntents.php I'm not that familiar with the configuration of PHP to know if it would do the trick...

Are there any switches to turn on in PHP in order for file() to "see" the query part? Something like allow_url_fopen? http://www.php.net/manual/en/ref.filesy ... -url-fopen
Simon Angell
Forum Commoner
Posts: 45
Joined: Fri Jan 24, 2003 12:14 am

Post by Simon Angell »

Thanks Michel.
You've hit the nail on the head with what i was trying to say. Cheers.

I have tried the thing you suggested, but it didn't work. i will d-load and installed the latest version of PHP now, currently i have 4.2.3.

Also, the script i will be using uses this...
<?php

$length = "260";
$url = "http://www.weatherzone.com.au/yourHomeP ... f2eeb571ed";
$grab_start = "<th>Forecast for Canberra</th></tr>";
$grab_end = "<small>CANBERRA AIRPORT&nbsp;&nbsp;149.2014&deg;E, -35.3049&deg;N&nbsp;&nbsp;Elev. 578m</td></tr>";

$open = fopen("$url", "r");
$read = fread($open, 20000);

$grab = eregi("$grab_start(.*)$grab_end", $read, $warnings);
...
the reason for this, i have been unsucessful in getting the first script to write to my web server - Only locally on my computer. so will be skipping the writing of the wztest.txt file in the first script and just getting the second script (the one that needs the data from the ref=#) to get the data itself. If you want me to explain further i will, right now though, im getting some sleep, 4am here. :roll:
DeGauss
Forum Contributor
Posts: 105
Joined: Tue Oct 22, 2002 9:44 am
Location: Gainesville, FL

Post by DeGauss »

You could always use cURL ;)
Post Reply