Jump to content

Help


Elnof

Recommended Posts

I've been programing in PHP for about 40 seconds (when I wrote this), and I've encountered a problem... Can anyone tell me why this doesn't work?

<html><body><?php include($_GET["page"] . ".html"); ?></html>

Link to comment
Share on other sites

Hi.. Dont do include directly like this.. be4 that check whether file is exist or not on your server..? And one more security issue whether that file from on your server only or remote host.. bcoz you used get so any one can also do "http://www.danger.com/virus.php" or any thing like this.. So keep all possible care while including file via GET method..Regards,Vijay

Link to comment
Share on other sites

You should always have a check before including a file directly with a GET

<?php	$page_list = array('home', 'info', 'whatever');	if(isset($_GET['page'])){		if(in_array($_GET['page'], $page_list)){			include($page_list[$_GET['page']].'.html');		}else{			die("Invalid Page");		}	}?>

Link to comment
Share on other sites

Thanks! I truly am pathetic at this... it only took 40 seconds to mess up. Thanks for all the help! EDIT -- I tried some of what you said, but it still doesn't work. Here's what I have:

<?php$URL="http://www.geocities.com/elnof.eopia/".$_GET['page].".html"; include($URL); ?>

Link to comment
Share on other sites

First: it's hard to tell why it doesn't work, it could be because the file doesn't exists or that $_GET['page'] has no value... Do you get any errors?Second: the code teng84 posted isn't any better/more secure than your own code (in the first post...)Third: The code -Mike- posted has problems; you need to maintain an array/list with allowed file, and it doesn't work...

class khtml_page extends khtml_plugin{	private $kh_obj;	private $pages = array();	public function __construct( )	{		$this->type = "page";	}	public function init( &$kh_obj )	{		$this->kh_obj = $kh_obj;		return true;	}	public function call( $type, $context, &$params, &$kh_obj )	{		kdebug( "pageCall( ) so=" . $GLOBALS['stopoutput'] );		if (($type != 'page') || (($context != 'bodyStart')&&($context != 'check')) || !$kh_obj->loggedIn() )			return true;		$GLOBALS['KHTML_'] = $kh_obj;		$page = '';		if (isset($_GET['p']))			$page = $_GET['p'];		else if (isset($_POST['p']))			$page = $_POST['p'];		return $this->runPage( $page );	}	public function runPage( $page )	{		kdebug( "runPage( $page ) so=" . $GLOBALS['stopoutput'] );		if (empty( $page ))			$page = 'default';		$file = $this->pages[ $page ];		if (empty( $file ))			$file = $this->treatFilename( $page ) . '.php';		if (!file_exists( 'pages/' . $file )) {			if (file_exists( 'pages/default.php' ))				$file = 'default.php';			else				return true;		}		if (!defined( '_KHTML_VALID' ))			define( '_KHTML_VALID', 1 );		if (file_exists( 'pages/includes/' . $page . '.class.php' )) {			include( 'pages/includes/' . $page . '.class.php' );		}		include( 'pages/' . $file );		return false;	}	public function addPage( $page, $file )	{		kdebug( "addPage( $page, $file ) so=" . $GLOBALS['stopoutput'] );		if (empty( $page ) || empty( $file ))			return false;		$this->$pages[$page] = $file;				return true;	}	public function removePage( $page )	{		kdebug( "removePage( $page ) so=" . $GLOBALS['stopoutput'] );		if (empty( $page ) || !isset($this->pages[$page]))			return false;		unset( $this->pages[ $page ] );		return true;	}	public function treatFilename( $f )	{		// If not allowing subdirs		// $f = basename( $f );		// If allowing subdirs...		$f = str_replace( '..', '', str_replace( 'include', '',					str_replace( 'http://', '', $f ) ) );		//  Don't allow abs.paths..		//   *nix		while (($f[0] == '/') && (strlen( $f ) >= 1))			$f = substr( $f, 1 );		//   Win..		while (($f[1] == ':') && (strlen( $f ) >= 3))			$f = substr( $f, 3 );		return $f;	}};

(not much comments...)EDIT: The last code you posted has several problems:1. <a href... is a HTML tag for linking to another page/URL, PHP doesn't understand it and it's not correct, include takes the path to the file...2. Don't use the URL (with domain etc) when including files that belongs to your own domain/Server...3. I don't get where you got the idea of doing it like that...

Link to comment
Share on other sites

Ok, thanks, I'll try that, see if it works. EDIT --It didn't work... Does any one here use Geocities? I'm using it because they said that they support PHP, but none of my files are working. Many that's the problem. Sorry, the "<a href" wasn't me, it was the forum editer... I'll fix it.

Link to comment
Share on other sites

Thanks, but I still get a blank page. You sure that they support PHP?

Yahoo does disables PHP error messages so add this to the top of your source and see if there is any errors
ini_set('display_errors', 1);

Link to comment
Share on other sites

Ok, you still shouldn't use a url (http://...) when including files..Here's some tips:Check the source of the file when you open the page in your browser (FF: Ctrl+U, or View Source when rightclicking..), do you see php-code? If you do: either the host doesn't allow PHP or the files isn't named correctly.Make sure the file(s) have the extension .php (or .php5 if that doesn't work)Make sure you use "long tags" (<?php), some hosts doesn't allow short tags (<?)If that doesn't fix it, make sure that it really has PHP support, check forums and perhaps customerservice...And my best tip and something I highly recommend:Install a webserver on your computer (or in your LAN) that you use when testing and developing in PHP, for windows there's packages such as WAMP and XAMPP which include apache (worlds most used webserver!?), MySQL and PHP (world most popular scriptlanguage......)It makes developing and learning PHP alot easier if you use your own, local, server, ex: no long waitingtimes when up-/downloading etc...
Link to comment
Share on other sites

I don't see PHP code. In fact, I don't see anything at all:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD><BODY></BODY></HTML>

Do you have a suggestion for different free web hosting that supports PHP?

Link to comment
Share on other sites

mr chisol is right so i dont know why your codes stil doesnt worki suggest try to look if the directory is right maybe the file is on the other folder or something hope that helps

Link to comment
Share on other sites

Thanks for all the help, but I think that I'm just gunna scrap my Geocities site, and get my PHP files hosted by someone else...

Link to comment
Share on other sites

First: tried http://www.geocities.com/elnof.eopia/ but there's no index-file, what's the file you are working on called??Second: I repeat: Insall XAMPP or WAMP on your computer for working with PHP, then when you are done, upload it to a host...

Link to comment
Share on other sites

$_GET is "standard", and include() belongs to "control structures", which that both are there, nomather how PHP is configured...what code do you use (complete.. Copy and paste it between

 and [/code box] (both without spaces...))?tried these urls (as I don't know what other files you have that I can try with..)http://www.geocities.com/elnof.eopia/pageL...us.net/somecodehttp://www.geocities.com/elnof.eopia/pageL...et/somecode.phphttp://www.geocities.com/elnof.eopia/pageL...et/somecode.txtBut I get nothing.. Not even an error... this is strange
Link to comment
Share on other sites

Thanks for all the help. But I figured it out... Apparently Geocities forgot to mention that it costs to use PHP... Thanks for the help. Do you have any idea where I might be able to host PHP files for free?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...