Vincent Von Nino Dapiton Vincent Von Nino Dapiton - 18 days ago 7
PHP Question

PHP header(location:) redirect with root directory

Is there a way to create a

header('Location:');
path that starts to the root directory.

Examples Like:

formaction="/cert/forms/sessions/session-inc-info.php"


or

include($_SERVER['DOCUMENT_ROOT'].'/cert/forms/sessions/session-inc-info.php');


cert is my root directory folder

ive been trying codes like

header('Location:'.$_SERVER['DOCUMENT_ROOT'].'/cert/forms/sessions/session-inc-info.php);


and

header('Location:/cert/forms/sessions/session-inc-info.php');


the only thing works for me is using
../


header('Location:../../../session-inc-info.php');


but it's hard for me because i have alot of folders and subfolders.
and i have so many scripts that have to be redirected.

Thanks.

so this is the sample folder structure

enter image description here

so the
content.php
will have a button that redirects to the
session.php
and i have done that already and now when the
session.php
script will have a
header('Location:');
that must redirect to the dashboard.php . now that is my problem. i don't now how to create the path like

cert---->dashboard----->dashboard.php

Answer
header("Location: http://".$_SERVER['HTTP_HOST'].$formaction;

location should contain URL, not server file path

Comments