Hello everyone! It has been a while for me. I have a quick question about PHP. I am working on a site that I use the echo and include "tags" a lot. I insert data from a form using _get to a php page. I put the data into a variable (eg. $data) and need to add .php to the end of it and combine it with an include. This is what I have so far but of course it does not work. Anyone have the correct way?
<? include '<? echo $data ?>.php' ?>
Are you a Google Analytics enthusiast?
Share and download Custom Google Analytics Reports, dashboards and advanced segments--for FREE!

www.CustomReportSharing.com
From the folks who brought you High Rankings!
More SEO Content
International SEM | Social Media | Search Friendly Design | SEO | Paid Search / PPC | Seminars | Forum Threads | Q&A | Copywriting | Keyword Research | Web Analytics / Conversions | Blogging | Dynamic Sites | Linking | SEO Services | Site Architecture | Search Engine Spam | Wrap-ups | Business Issues | HRA Questions | Online Courses
Php Coding
Started by
Gatorhardware
, Jan 23 2005 12:30 PM
5 replies to this topic
#1
Posted 23 January 2005 - 12:30 PM
#2
Posted 23 January 2005 - 01:43 PM
I would change the $data variable after it's been called into the page. Also, no need for the echo since you're already in PHP mode. Something like the following should work, assuming you already have the $data variable established.
Or if you don't want to reset $data to add the .php part you should also be able to do something like:
HTH
CODE
<?
$data = $data . ".php";
include($data);
?>
$data = $data . ".php";
include($data);
?>
Or if you don't want to reset $data to add the .php part you should also be able to do something like:
CODE
<?
include($data . ".php")
?>
include($data . ".php")
?>
HTH
#3
Posted 23 January 2005 - 05:08 PM
The extra <? is doing you in, as is the echo. Once you have... never remember the term for this "opened php", you can't do it again... if that makes sense
Also, echo writes to the browser window. So what you are coding says to print out whatever $data holds, as part of an include. No idea what errors this will throw, or how PHP will handle it, but it will throw a bunch!!!
Also, echo writes to the browser window. So what you are coding says to print out whatever $data holds, as part of an include. No idea what errors this will throw, or how PHP will handle it, but it will throw a bunch!!!
#4
Posted 24 January 2005 - 04:37 AM
Thank you Randy and Projectphp. That is what I needed. I knew I could count on everyone here!
#5
Posted 24 January 2005 - 11:13 AM
WOAH!! Woah!!
Are you including files with names based on user submitted input?
This is a HUGE security risk.
A MUCH better idea is to do something like this:
Are you including files with names based on user submitted input?
This is a HUGE security risk.
A MUCH better idea is to do something like this:
CODE
$myincludes[0] = "blah.php";
$myincludes[1] = "blah1.php";
$myincludes[2] = "blah2.php";
$myincludes[3] = "blahblah.php";
$myincludes[4] = "abcde.php";
$choice = intval($data);
if($choice <0 || $choice > 4){
echo("Error...");
}else{
include($myincludes[$choice]);
}
$myincludes[1] = "blah1.php";
$myincludes[2] = "blah2.php";
$myincludes[3] = "blahblah.php";
$myincludes[4] = "abcde.php";
$choice = intval($data);
if($choice <0 || $choice > 4){
echo("Error...");
}else{
include($myincludes[$choice]);
}
#6
Posted 24 January 2005 - 12:25 PM
QUOTE(sherri @ Jan 24 2005, 12:13 PM)
WOAH!! Woah!!
Are you including files with names based on user submitted input?
This is a HUGE security risk.
A MUCH better idea is to do something like this:
Are you including files with names based on user submitted input?
This is a HUGE security risk.
A MUCH better idea is to do something like this:
CODE
$myincludes[0] = "blah.php";
$myincludes[1] = "blah1.php";
$myincludes[2] = "blah2.php";
$myincludes[3] = "blahblah.php";
$myincludes[4] = "abcde.php";
$choice = intval($data);
if($choice <0 || $choice > 4){
echo("Error...");
}else{
include($myincludes[$choice]);
}
$myincludes[1] = "blah1.php";
$myincludes[2] = "blah2.php";
$myincludes[3] = "blahblah.php";
$myincludes[4] = "abcde.php";
$choice = intval($data);
if($choice <0 || $choice > 4){
echo("Error...");
}else{
include($myincludes[$choice]);
}
Hi sherri, No this was just for loading a file in a table cell. Thank you for the example though, I think I have a use for that.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users









