php: problem with variable when using header location

Joined
12 Feb 2006
Posts
17,720
Location
Surrey
i have always managed rto have this working, now i go back to add more to the code and it now doesn't work and i have no clue why.

basically as all my pages are on my machine i decided that every page would include one page straight away by using $_SERVER['DOCUMENT_ROOT'] which defines a variable called $root. this variable defines the path on my machine to get to the root folder for the site i'm working on which is deeper then htdocs.

for the user login page i orignally had it only redirect the user to one specific page if already logged in and after logging in take the user to that page whicjh was defined as $root . "member/pagetogoto.php" this worked until i added the ability to choose either previous page, member page or hmoe page.

to go to previous page i use $_SERVER["REQUEST_URI"] which isn't the previous page but curent but to the user it looks like previos page. this keeps all the variables in the url so returning to what the page should be as before.

this works when the user chooses the previous page when logging in however when choosing home page or member page as this uses the $root variable the page is never redirected only refreshed. at first i though i may have needed to use global $root as perhaps i was too deep in the code to use $root but then the first thing the page does is check if logged in and if so redirect to $root . "memberpage.php which doesn't work no more either.

so why might the $root variable not be working when using header location to redirect? if i echo $root out instead of redirect then it echo's as expected so really stuck

sorry for long post but firgured i'd explain the whole situation

thanks for any help
 
Last edited:
why? :confused:

for multiple sites, use virtual hosts within your httpd.conf if you're using apache. :)

what does virtual hosts give me then?

the reason i did that was as one file could be included from many different locations so if i made any include or header, pretty much anything start from $root then i could place the file anywhere i wanted and everything would still work, where as before i had to keep changing the amount of ../ dependent on what file is including the information.
 
are you running multiple sites? you only need virtual hosts setup if you're doing that. each site has it's own document root.

and configure yourself an includes directory in your php.ini - then you can include files regardless of folder structure.

PHP:
include 'foot.php';

that would work from

Code:
website1/htdocs/index.php

and also from

Code:
website26/htdocs/loads/of/folder/levels/deeper/index.php
 
are you running multiple sites? you only need virtual hosts setup if you're doing that. each site has it's own document root.

and configure yourself an includes directory in your php.ini - then you can include files regardless of folder structure.

PHP:
include 'foot.php';
that would work from

Code:
website1/htdocs/index.php
and also from

Code:
website26/htdocs/loads/of/folder/levels/deeper/index.php

oh blooming heck. you serious that all i have to do is define where foot.php is i php.ini and thats it? gosh getting the $root thing to work as desired took me ages wish i had known this ages ago :p

so how would it know that foot.php isn't same folder? does it just do a quick check first saying if foot.php location is defined then use that else choose same folder as current?

any good places to learn about php.ini and these sort of things as every now and again i see people mention stuff but never understand.

thanks marc for the help
 
so how would it know that foot.php isn't same folder? does it just do a quick check first saying if foot.php location is defined then use that else choose same folder as current?
p

it checks the current folder first. if the file doesn't exist, then it goes off and checks your includes dir. :)
 
needing some help again

ok so i have found the php.ini file and after reading up on a load of google search's i think i have found the place i am looking for, the path and directories area, which has include paths for unix and windows, windows being uncommented.

now what is it i need to do here so i can define the paths for many files. i really am lost and google is not giving me the help needed. i have tried a few things which don't work but then i am also unsure what to do after changing the php.ini file, do i need to restart apache? do i need to do something in my files which are including say file1.php?
 
yes you do need to restart apache after making changes to php.ini. :)

with this php.ini setting, you are setting an "includes" folder (d:\includes for example). so plonk all your files to be included inside the folder and you can access them as i mentioned above without specifying a path. it really couldn't be easier.... :p
 
ok weird problem. i had it working and now for no reason it isn't.

at first it kept including from the default folder Xampp\php\pear even after i change it to new location, save the file and then restart apache.

just to ensure there was no spelling mistakes i copied and pasted the folder location although nothing changed it then started working.

from reading online how to do this it appears i can use multiple folder (is that correct?) so i tried adding another how it said but then everything screwed up after that going back to the default folder and now nothing will get it to change.

is there some sort of if folder location is incorrect then use default setting or seomthing. or perhaps am i just no restarting apache correctly? i have tried the xampp_restart button and also from xampp control panel stopped and started apache many times but no change.

any reason why this is happening?

also am i right in thinking i can have more then one include folder? if so how do i seperate the folders so i knows one location from another? from what i have read i need the paths on the same line, one site is saying seprate with a semi colon but i can't tell if this is correct with the above problem.

finally i'm still lost as to what the .; means at the beggining of the include_path.

sorry for asking so much i am going off searching a lot before asking here. think my mind must not be in the right place today or something

[edit]

which include_path should i be changing? unix or windows?
 
Last edited:
finally i'm still lost as to what the .; means at the beggining of the include_path.

i have no idea and i don't care either. :p i just do whatever it takes to work. here's mine as an example....

Code:
include_path = ".;d:\server\includes"

any particular reason for needing to use multiple folders? i doubt you need to really..... but if you do just seperate them with a ; - i think the examples are clear enough.

as for you problems with xampp/php.ini - haven't a clue. i install apache manually and unzip php to a folder. don't like faffing about with these packages.... :p
 
Last edited:
i have no idea and i don't care either. :p i just do whatever it takes to work. here's mine as an example....

Code:
include_path = ".;d:\server\includes"
any particular reason for needing to use multiple folders? i doubt you need to really..... but if you do just seperate them with a ; - i think the examples are clear enough.

as for you problems with xampp/php.ini - haven't a clue. i install apache manually and unzip php to a folder. don't like faffing about with these packages.... :p

thanks for the reply. i guess something is wrong with my machine then as nothings is changing even after a restart the machine which will be why everything i have tried that i have tead online isn't working.

i was planning on using multiple folders so that it keeps everything much tidier, keeping the files that deal with membership in member folder, files deal with the site in another etc, but i can always just say include "member/login.php" so that's fine just easier to not have to include the member/ part.

ok will keep trying to get this to work if not will try a reinstall.

thanks again
 
i was planning on using multiple folders so that it keeps everything much tidier, keeping the files that deal with membership in member folder, files deal with the site in another etc, but i can always just say include "member/login.php" so that's fine just easier to not have to include the member/ part.

ok i can see why you want multiple folders. but you still only have to specify the filename even with mutliple folders. that's the whole point of this.... :p
 
ok i can see why you want multiple folders. but you still only have to specify the filename even with mutliple folders. that's the whole point of this.... :p

yeah exactly :) just was saying as atm i can't get it to work so it's fine, however as you have said when i get it working i can use ; to use multiple folders then all i have to do is specify the file name, which will be much easier then the current method.
 
Back
Top Bottom