Log in

View Full Version : Help with PHP script



Wildfire563
10-01-2007, 01:54 AM
Hi,
I am absolutely clueless when it comes to PHP scripting. I've spent a couple of hours reading through a manual on PHP, but I can't even figure out where to begin.

My application, I think, is fairly simple.

I have an executable which uses an internal web browser. In it, there are several commands which I would like to replace with my own commands. In particular, the program has a call

http://www.navinfo.org/apt.php?id=%s Where %s would be replaced with the name of a facility which I can select on a map.

I'd like to replace it with

http://www.airnav.com/aiports/%s

but when I replace the first command with the second it only outputs

http://www.airnav.com/airports

The airports facility search page, and doesn't give me the particular page I am looking for.

So it occurred to me, since I am limited to a maximum of 40 characters for each command, and airnav.com doesn't appear to have an ability read programmatically; I could host a php script which, when passed a variable, outputs the correct string I want to the program which is running the script.

So what I am thinking of is just something simple, like, in the executable:

http://www.fssetup.com/apt.php?id=%s

which runs

apt.php, which contains:
<?php
print("http://www.airnav.com/airports/"+$id)
?>

Of course this doesn't work, I get back a 404 error. Could somebody please help me develop this application? I don't even know how to set up the php file or where to put it. I'm assuming I can just put it in my root directory at my website and it should just work if properly written.

insanemonkey
10-01-2007, 03:32 AM
have you tried using arrays... im not sure how to do this... but you should try something like..



<?php

$pages = Array(

'aiports/%YOURID%' => 'http://www.airnav.com/apt.php?id=%yourID%',

);

if (isset($_GET['page']) && array_key_exists($_GET['page'],$pages)) {
include($pages[$_GET['page']]);
}
else {
include('YOUR MAIN PAGE');
}
?>


but this would output something like this lol..
http://yoursite.com/?page=/aiports/"and id here"

I dont know if this would work.. but this is an example of something you could try....

Wildfire563
10-01-2007, 11:09 AM
I think perhaps I wasn't clear enough about what I am trying to do?
And I'm wondering if what I am trying to do is even possible?

navinfo.org calls up particular pages at the site by calling its php scripts and passing variables in the URL.

So, for instance, if I want to get information about Nashua, NH airport I would write in the browser http://www.navinfo.org/apt.php?id=KASH

(KASH is the airport's ICAO identifier).

airnav.com works based on straight url entries. So for airnav.com, to go to its page about Nashua, NH airport (which has a lot more information than navinfo.org's site), you would type in the URL

http://www.airnav.com/airports/KASH

So here I am using a flight planner program. At the top of the program window are some tabs, and one of the tabs is a map. In the map, if you right click on a facility (like an airport or navigation aid) you can select to get information about the facility in a couple of ways. If you select "Information", it opens a separate little window (an internet browser window essentially) and shows the web page for the facility of interest. You can also select a different option, and for this it opens a different tab in the program window and, again, shows the web page for the facility of interest. But navinfo.org stinks in terms of the information it gives. I'd rather see the page from airnav.com for the facility in the programs browser windows.

So, if you use a hex editor to look at the program's executable, it turns out you can find the commands that the program uses to call the web pages. There are three different commands depending on the type of facility (Airport, Navaid, Airspace Fixes). Each has space for 40 characters. The commands look like

http://www.navinfo.org/apt.php?id=%s....
http://www.navinfo.org/navaid.php?id=%s.
http://www.navinfo.org/fixid.php?id=%s...

Where %s I assume is a string that is being passed to the url and the url is being entered and used by the program and the web page is being displayed. But if I replace these lines with

http://www.airnav.com/airports/%s.......
http://www.airnav.com/navaids/%s........
http://www.airnav.com/airspace/fix/%s...

I don't get the expected results (expected by me, anyway). What I get is just http://www.airnav.com/airports/.

Sooo, I'm assuming that %s must produce gobbleygook for the url line and airnav.com is just throwing the information away because it doesn't know what to do with it. So my next thought is, well, what if I create a php script web page similar to what navinfo.org is doing that displays the airnav.com page instead? First of all, then I can see what is being passed by %s so I can do a little debugging, second, once I understand that, I can process that input however I want, and my command is the same size as the original command. So I could replace it with something like http://www.fssetup.com/apt.php?id=%s

But, as I said, I don't know PHP at all. From my limited study of http://hudzilla.org/phpwiki/index.php?title=Main_Page, well, I assumed, if I broke down the url being sent that:

http://www.navinfo.org/apt.php?id=%s
calls a script called apt.php placed in the root directory of the web site,
and that the line passes a variable called id that is filled with %s.

I assumed that the variable is used in the PHP script by saying $id? But you seem to be using the variable by saying %id%?

So maybe that is part of my problem. I'm sure I have other syntax mistakes, like, I have no idea how to actually call up the web page in the browser window. I assumed that print would then send the command I constructed. You seem to be using include instead of print?

I'm confused by why you are choosing to fill an array? Why not just construct the line directly like I thought I was doing (using a + sign)?

Like I said, I'm clueless.

Wildfire563
10-03-2007, 02:06 AM
Ok as always, the more you learn, the more you realize you don't know. Before, I just didn't know anything. Now I've worked through some more, but now I realize I know even less. At least I can describe what I want to do more clearly.

I want to be able to use a php script to build a url using a variable, and then display that url.

I've tried the above example, and I've tried to modify it to use file_get_contents (plus a bunch of other stuff...)

Here's my latest example code:


<?php

$pages = Array(

$_GET['id'] => 'http://www.airnav.com/airport/',

);

if (isset($_GET['id']) && array_key_exists($_GET['id'],$pages)) {
file_get_contents($pages[$_GET['id']]);
}
else {
file_get_contents('http://www.airnav.com/airport/');
}?>


You can test it by http://www.flyingscool.com/apt.php?id=KASH

Problem is, I get an error:

Warning: file_get_contents(http://www.airnav.com/airport/) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/flyingsc/public_html/apt.php on line 10
Array

Am I blocked from opening a page this way by the site's page I am trying to display?

Is my code totally wrong (I believe so)?

Help!

Thanks!

Wildfire563
10-03-2007, 02:07 AM
Ok as always, the more you learn, the more you realize you don't know. Before, I just didn't know anything. Now I've worked through some more, but now I realize I know even less. At least I can describe what I want to do more clearly.

I want to be able to use a php script to build a url using a variable, and then display that url.

I've tried the above example, and I've tried to modify it to use file_get_contents (plus a bunch of other stuff...)

Here's my latest example code:


<?php

$pages = Array(

$_GET['id'] => 'http://www.airnav.com/airport/',

);

if (isset($_GET['id']) && array_key_exists($_GET['id'],$pages)) {
file_get_contents($pages[$_GET['id']]);
}
else {
file_get_contents('http://www.airnav.com/airport/');
}?>


You can test it by http://www.flyingscool.com/apt.php?id=KASH

The URL I want to create with this is http://www.airnav.com/airport/KASH

Problem is, I get an error:

Warning: file_get_contents(http://www.airnav.com/airport/) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/flyingsc/public_html/apt.php on line 10
Array

Am I blocked from opening a page this way by the site's page I am trying to display?

Is my code totally wrong (I believe so)?

Help!

Thanks!

twohawks
10-08-2007, 07:43 PM
I found some great discussions on php url re-writing on the punbb (http://www.punbb.org) as well as the related punres forums.
Hope this helps.