Page 2 of 2

Re: php include code problem

Posted: Thu Aug 20, 2009 11:34 am
by mohsin360
ya i find it and do it

Re: php include code problem

Posted: Fri Aug 21, 2009 7:36 am
by mohsin360

Code: Select all

<?php
$path="/home/jcipakis/public_html/mohsin3/";
$msn=basename($path,".php");
echo $msn;
?>

this code tells me only directory but not the filename
my file store in public_html/mohsin3 and name of my file is index3.php

when i visit the page it prints mohsin3 the last folder of my dir ?
what can i do?

Re: php include code problem

Posted: Fri Aug 21, 2009 7:55 am
by jackpf
I don't really understand what you're trying to do, but to include files from an absolute path, you can do this:

Code: Select all

include $_SERVER['DOCUMENT_ROOT'].'/index3.php';

Re: php include code problem

Posted: Fri Aug 21, 2009 8:45 am
by mohsin360
i have a file A and name of file a is index.php
i want it to find its own name and if its name is index.php it changes it to index3.php and if it find its own name index3.php it will dont doany thing

Re: php include code problem

Posted: Fri Aug 21, 2009 9:25 am
by Eran
you can use the __FILE__ magic constant that gives you the current complete path + file name.

Code: Select all

$file = basename(__FILE__);
if( $file == 'index.php' ) {
    header('Location: index3.php');
}
 

Re: php include code problem

Posted: Fri Aug 21, 2009 11:04 am
by mohsin360
i tried this

Code: Select all

<?php
 
$filename= basename(__FILE__);
$newname= include "newname.txt" ;
$oldname= include "oldname.txt" ;
 
if($filename != $newname){
 
rename("$oldname","$newname");
}
else{
header('Location: $newname');
}
 
 
?>
the two files newname.txt have text [new.php]
and oldname.txt have text [old.php]


but does not work i think there is some problem about names
it shows me

new.phpold.php
Warning: rename(1,1) [function.rename]: No such file or directory in /home/a2992386/public_html/mohsin4/index.php on line 9

Re: php include code problem

Posted: Fri Aug 21, 2009 11:34 am
by cpetercarter
If you write

Code: Select all

$newname = include "newname.txt";
 
$newname will have the value 1 if the include is successful or 0 if it is not successful. It will not contain the text of whatever is written in "newname.txt". To do this, you need to open and read "newname.txt" into $newname.

Re: php include code problem

Posted: Fri Aug 21, 2009 12:34 pm
by mohsin360

Code: Select all

<?php
 
$filename= basename(__FILE__);
$newname= readfile("newname.txt");
$oldname= readfile("oldname.txt");
 
if($filename != $newname){
 
rename("$oldname","$newname");
}
else{
header('Location: $newname');
}
 
 
?>
i tried this but results are same

it shows
new.phpold.php

Warning: rename(7,7) [function.rename]: No such file or directory in /home/a2992386/public_html/mohsin4/index.php on line 9

Re: php include code problem

Posted: Fri Aug 21, 2009 2:32 pm
by mohsin360
so what can i do now ?
and error is not in
header statement it shows in rename statement