PHP Help. - ? in URLS
Moderator: General Moderators
-
Simon Angell
- Forum Commoner
- Posts: 45
- Joined: Fri Jan 24, 2003 12:14 am
PHP Help. - ? in URLS
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
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
-
Simon Angell
- Forum Commoner
- Posts: 45
- Joined: Fri Jan 24, 2003 12:14 am
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.
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
-
fractalvibes
- Forum Contributor
- Posts: 335
- Joined: Thu Sep 26, 2002 6:14 pm
- Location: Waco, Texas
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.
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
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 ?.
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?
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?
-
Simon Angell
- Forum Commoner
- Posts: 45
- Joined: Fri Jan 24, 2003 12:14 am
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???
Last edited by Simon Angell on Tue Jan 28, 2003 8:08 am, edited 1 time in total.
- puckeye
- Forum Contributor
- Posts: 105
- Joined: Fri Dec 06, 2002 7:26 pm
- Location: Joliette, QC, CA
- Contact:
I think I'm getting what Simon is saying...
What I can understand is that the file() function
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
What I can understand is that the file() function
Code: Select all
file('http://www.weatherzone.com.au/yourHomePage.jsp?ref=f2eeb571ed')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
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 149.2014°E, -35.3049°N 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.
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 149.2014°E, -35.3049°N 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.