Jump to content

Recommended Posts

Hey there,

 

Wondering if anyone could assist me with something that is actually pretty simple for someone who knows their PHP.

 

I don't know enough to be able to write from scratch (learning), whilst i can generally edit existing samples to fit my needs.

 

Please see the attached file which is a description of my problem and my solution to it... i just require help with the correct syntax/writing the code.

 

if u look at the attachment, the code hightlight in red is what i'm trying to achieve (just not written correctly for php to process).

 

Thanks in advance.

 

Anthony.

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/50939-solved-please-advisehelp-thanks/
Share on other sites

ok with the assistance of an old friend i got this far;

 



<?PHP

<!-- this will list the directory that you are actually in e.g. "member1" -->
$Member = dirname ($_SERVER[php_SELF]);

echo $member

<!-- now you have that you can just include it in the path for the header to make the right path name -->
$header="../headers/header_".$Member.".html";

?>

<? include("$header") ?>
<? include("current.html") ?>

 

however something seems wrong because the page just shows up blank?

You have a syntax error.

 



<?php
// note this is only an html comment not a php comment
// <!-- this will list the directory that you are actually in e.g. "member1" -->
$Member = dirname($_SERVER['PHP_SELF']); // array index references should always be enclosed with single quotes.

echo $member

//<-- now you have that you can just include it in the path for the header to make the right path name -->
$header="../headers/header_".$Member.".html";

?>

<?php 
include("$header") // should always use <?php
?> 
<?php include("current.html") ?>

ok i stripped out all the comments and this is what i've got:

 


<?php
$Member = dirname($_SERVER['PHP_SELF']); // array index references should always be enclosed with single quotes.
$header="../headers/header_".$Member.".html";

echo $Member;
?>

<?php include("$header") ?><?php include("current.html") ?>

 

i get the current.html showing, but the header is not showing.

i do, however, get "/members/member1" at the top of the page, where the header should be...

 

i can't work out why the header isn't showing?

 

Path is correct...

Are you sure that file exists. Because what you are essneitally trying to include is this:

 

../headers/header_/members/member1.html

 

That does not seem like a valid file to me, but it maybe. I would check that and verify you are looking in the right direction.

 

It also might be wise to turn on error reporting. Those syntax errors should have been visiable but are not due to php.ini configuration settings.

../headers/header_/members/member1.html

 

thats not what i wish to include.

 

../headers/header_member1.html is what i wish to include...

 

really appreciate your help!

 

Current code:

 

<?php
$Member = dirname($_SERVER['PHP_SELF']);
$header="../headers/header_".$Member.".html";
?>

<?php include("$header") ?>
<?php include("current.html") ?>

<?php
list(,$Member) = split("/", dirname($_SERVER['PHP_SELF']);
$header="../headers/header_".$Member.".html";
?>

<?php include("$header") ?>
<?php include("current.html") ?>

 

The dirname is the full path to the php_self. In order to get away from that using the split function www.php.net/split and list www.php.net/list you can have $Member only contain the last part of the dir given that the DIR only has 2 parts to it. IE: members and members1

 

Note the code above is untested and may need tweeking.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.