Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google      Sign In   
  • Create Account

Subscribe to HRA Now!

 



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!


Sponsored Content

 

 
 

Photo
- - - - -

Php Coding


  • Please log in to reply
5 replies to this topic

#1 Gatorhardware

Gatorhardware

    Web Hoster

  • Active Members
  • PipPipPipPipPip
  • 315 posts

Posted 23 January 2005 - 12:30 PM

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' ?>

#2 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

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.

CODE
<?
$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")
?>

HTH

#3 projectphp

projectphp

    Lost in Translation

  • Moderator
  • 2,203 posts
  • Location:Sydney Australia

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 unsure.gif

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 Gatorhardware

Gatorhardware

    Web Hoster

  • Active Members
  • PipPipPipPipPip
  • 315 posts

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 sherri

sherri

    Perceptum et Invenio

  • Active Members
  • PipPipPip
  • 89 posts
  • Location:Lost in Canada

Posted 24 January 2005 - 11:13 AM

WOAH!! Woah!!

Are you including files with names based on user submitted input?

eek.gif

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]);
}


#6 Gatorhardware

Gatorhardware

    Web Hoster

  • Active Members
  • PipPipPipPipPip
  • 315 posts

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?

eek.gif

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]);
}

View Post


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