TeamPhotoshop
Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
Forum Home Latest Posts Search Help Subscribe

PHP: Grabbing file from URL for template

Page: 1 Reply
Jan 9th 2003#85041 Report
Member since: Sep 2nd 2002
Posts: 7
I want to be able to use a single template file and choose what data I want to display on it based on the variables in the url.

For this simple example, I have this php file, called hello.php, saved in the same dir as the text files I want to use. Each text file is named in the "default_1101.txt" format, with a "default.txt" in place as an error catcher. I want to use the link style of "hello.php?vid=1101" to get this all to display. I'm getting the following error: Parse error: parse error, unexpected T_STRING in /home/hellatoms/public_html/temp52/an_data/hello.php on line 7.

Here's the code in hello.php:

[QUOTE]




if(!$_GET['vid']){
_ _include("default.txt"); _
}else{
_ _include("default_". $_GET['vid'] .".txt");
}

?>




[/QUOTE]
Reply with Quote Reply
Jan 9th 2003#85068 Report
Member since: Apr 1st 2002
Posts: 1487
heh, i can see some things wrong with this off the top of my head, but i have to get to school, so maybe paavo, or sidez can help ya out. if not, i'll see what i can do after school.
Reply with Quote Reply
Jan 9th 2003#85091 Report
Member since: Mar 20th 2001
Posts: 3367
Not sure what you wrote but here's my code
[php]

if(!$vid){
include("default.txt");
}

else{
include("default_$vid.txt");
}

?>
[/php]

Demos :

Default : http://tmp.phex.net/default/default.php
101 : http://tmp.phex.net/default/default.php?vid=101
102 : http://tmp.phex.net/default/default.php?vid=102

Text Files : http://tmp.phex.net/default/default.txt
101 : http://tmp.phex.net/default/default_101.txt
102 : http://tmp.phex.net/default/default_102.txt
Reply with Quote Reply
Jan 9th 2003#85182 Report
Member since: Sep 2nd 2002
Posts: 7
Using your exact code, I get the following error:

Fatal error: Call to undefined function: ÊÊÊÊinclude() in /home/hellatoms/public_html/temp/stuff/test.php on line 12

Line 12 would come out to be the include("default_$vid.txt"); line. Would you be able to post the files in a zip, because I can't fathom what's going wrong during my copy and paste.
Reply with Quote Reply
Jan 9th 2003#85183 Report
Member since: Apr 1st 2002
Posts: 1487
it might be because of some weird spaces there. i noticed in the error there were 4 Ê's in front of include and there are 4 spaces in front of include in Sidez's code. just a though.
Reply with Quote Reply
Jan 9th 2003#85203 Report
Member since: Mar 20th 2001
Posts: 3367
[php]
if(!$vid){include("default.txt");}
else{include("default_$vid.txt");}
?>
[/php]

Tabs for cleaner coding . What server are you running?
Reply with Quote Reply
Jan 10th 2003#85207 Report
Member since: Sep 2nd 2002
Posts: 7
Yep, the spacing was the problem. Thank you guys, you've been a huge help.
Reply with Quote Reply
Jan 10th 2003#85243 Report
Member since: Jun 30th 2001
Posts: 447
Hellatoms, you have a ****ed up PHP configuration because you should be able to use tabs and spaces in your code with no problem.
Reply with Quote Reply
Page: 1 Back to top
Please login or register above to post in this forum