php help

Associate
Joined
1 Mar 2006
Posts
425
im trying to make links like this

www.example.com/index.php?page=Example_page

im trying code like the below in the PHP File

Code:
<?php
 $Example_Page = "http://www.example.com/example2.htm";} 
?>

and this is the html

Code:
<html>
<a href="http://www.example.com/?page=Example_Page">click</a>
</html>
from clicking

www.example.com/index.php?page=Example_page

want to be able to go to

www.example.com/example2.htm

this doesnt work what am i doing wrong

hope this makes sense

any help would be nice

thanks
 
I think you have to use the $_GET function at the top of each page. I did have a code, but I am away from home at the moment so cannot access the file.
 
in example.php:

PHP:
$page_suffix = '.htm';
$dir = $_SERVER['DOCUMENT_ROOT'] . 'include_pages/';
$file_path = $dir . '%s' . $page_suffix;

if (file_exists(sprintf($file_path,$_GET['page'])) && is_file(sprintf($file_path,$_GET['page']))) {
  require_once(sprintf($file_path,$_GET['page']));
} else {
  die(sprintf($file_path,$_GET['page']) . 'doesn\'t exist, sorry!');
}

I'm not sure what you're after, but that will (untested) check the query string at position page=Page (eg www.example.com/?page=Page) and check if the file Page.htm exists in the directory include_pages, if it exists, it'll include it, if not, you'll get an error.

like I said, totally untested, but that's the premise!
 
Warning: key() [function.key]: Passed variable is not an array or object in /home2/denbyuk/public_html/example.php on line 2
 
hmm, I never can get the hang of using that straight off the bat! :o

I thought of a better way anyway:

PHP:
 foreach ($_GET as $param => $value) {
  printf('<param name="%s" value="%s" />',$param,$value);
 }
 
tryed chaning it to

foreach ($_GET as $param => $value) {
printf('<param name="%s" value="%s" /><br>',$param,$value);
}
but it still stayed on the same line but included <br> :P
 
change the <br> to <br /> ?

edit: unless you mean in the source?

Code:
 printf('<param name="%s" value="%s" />%s',$param,$value,"\n");
 
yea im using

printf('<PARAM NAME="%s" value="%s">',$param,$value,"\n");


not creating newline in the view source :(

Code:
  printf('<PARAM NAME="%s" value="%s">%s',$param,$value,"\n");
copy that, you're missing the final %s which will inject the newline.

and as psyreen says, if you're doing this on a public scale, you might want to set up a block list, and use addslashes as well
 
Back
Top Bottom