7 replies [Last post]
OPTAdmin
Offline
Enthusiast
Dover, OH -- Soon to be Columbus, OH
Last seen: 18 years 18 weeks ago
Dover, OH -- Soon to be Columbus, OH
Joined: 2004-07-27
Posts: 108
Points: 0

Okay, I'm new to PHP, and I figure it'll make my job alot easier if I can figure it out.

What I want to do:

I have a webpage that has a bunch of football schedules on it. Rather than type up each schedule and displaying it, is it possible to link to a certain PHP-thing that has the variables for the schedule itself, and then it can just display it?

Here is the PHP page that I'm looking to use:

http://www.ohiopreptalk.com/phptesting/test.php

I think I'm making sense, but I bet I'm not.
I'll simplify:

I have a template page with multiple variables. I want to have the template link to an external file in order to define those variables.

Also, I want to be able to click on the team name from the list of teams, and have it go through the external file and load the template page with the correct information for that team.

Yeah wow, I sound like I'm babbling.

I am going to be attending The Ohio State University this fall as an incoming freshman, majoring in Computer Science and Engineering.

Go Bucks!

Tags:
Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 weeks 15 hours ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5344
Points: 2965

PHP Question

Hi OPTAdmin,
I think what you are looking for is a way to include the variables.
Put this somewhere on your template to give access to the file containing the variables.

<?php 
include("myvars.php"); 
?>


Then on the page called myvars.php have:
<?php 
$varOne="something"; 
$anothervar="something else"; 
?>
Then to use them on your template
<?php 
echo "I want $varOne but could only get $anothervar"; 
?> 
should give you
Quote:
I want something but could only get something else

Hope that helps

OPTAdmin
Offline
Enthusiast
Dover, OH -- Soon to be Columbus, OH
Last seen: 18 years 18 weeks ago
Dover, OH -- Soon to be Columbus, OH
Joined: 2004-07-27
Posts: 108
Points: 0

PHP Question

Okay, I could do that all well. That much worked.

Is it possible to load a certain external file when I click on the link? Meaning, I want to load a different external PHP file for each link. For example:

If I click on St. Edward, I want the stedward.php file to be loaded for the template. If I click on Dover, however, I want the dover.php file to be loaded.

Any ideas there?

I am going to be attending The Ohio State University this fall as an incoming freshman, majoring in Computer Science and Engineering.

Go Bucks!

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 weeks 15 hours ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5344
Points: 2965

PHP Question

Hi OPTAdmin,
Yes, you could make the links something like: "/index.php?content=stedward"
then in the template file "index.php" where you want to display the content use

<?php
/*allowable content pages */
$contypes= array("stedward", "dover");

/* check that a valid content page has been requested.*/
 if(isset($_GET['content']) && in_array($contypes, $_GET['content'])){
   include($_GET['content'].".php");
}else{
   echo"No content available.";
}

Hope that helps

OPTAdmin
Offline
Enthusiast
Dover, OH -- Soon to be Columbus, OH
Last seen: 18 years 18 weeks ago
Dover, OH -- Soon to be Columbus, OH
Joined: 2004-07-27
Posts: 108
Points: 0

PHP Question

Hmmm, that would actually take alot of time, because I have about 500 schedules to load in.

I asked the same question on PHPBuilder.com and got this reply:

Quote:
link to the template file and pass a GET varibale to specify which other file to include in the template:

code:
<a href="template.php?file=some_other_file">link</a>

warning! if you are going to do this be sure to properly validate the GET variable. perhaps store a list of allowable variables in an array and use in_array() to check.

Once again, I am close to illiterate when it comes to PHP. Any help with that?

I am going to be attending The Ohio State University this fall as an incoming freshman, majoring in Computer Science and Engineering.

Go Bucks!

OPTAdmin
Offline
Enthusiast
Dover, OH -- Soon to be Columbus, OH
Last seen: 18 years 18 weeks ago
Dover, OH -- Soon to be Columbus, OH
Joined: 2004-07-27
Posts: 108
Points: 0

PHP Question

Okay, I got it working now. I figured out what they meant by that above line.

Now they say:

Quote:
Now you need to find a way to check that the file being inlcuded is valid. If you dont your leaving your server wide open to hackers.

Any help with that, which doesn't include putting all 500+ schedule php files on there? Thanks in advance, of course.

I am going to be attending The Ohio State University this fall as an incoming freshman, majoring in Computer Science and Engineering.

Go Bucks!

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 weeks 15 hours ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5344
Points: 2965

PHP Question

Hi OPTAdmin,
Since you have too many file to include in an array things get a little tricky.
If possible name all the files incrementally like 001 to 500 that way you can check if the file is between those values and if so you have a valid file.
Otherwise you could use file_exists to test if the file exits before including it.

Hope that helps

OPTAdmin
Offline
Enthusiast
Dover, OH -- Soon to be Columbus, OH
Last seen: 18 years 18 weeks ago
Dover, OH -- Soon to be Columbus, OH
Joined: 2004-07-27
Posts: 108
Points: 0

PHP Question

Tony,

Actually, I thought of that. I'm actually using a four digit number, so it should be a little easier to check, I think.

I am going to be attending The Ohio State University this fall as an incoming freshman, majoring in Computer Science and Engineering.

Go Bucks!