Jump to content

Recommended Posts

Is it possible to do an include with a path variable and file name in the part between quotes ?

example

 

I have a path variable $_SESSION['path'] and I would like to include

 

$_SESSION['path'];

include"rotate.inc";

include"stylesheet.inc";

 

this works

$_SESSION['path'];

$file=$_SESSION['path'].'rotate.inc';

include"$file";

 

I would like something like

include"$_SESSION['path']rotate.inc";

 

but I can not get it to work.

 

kind regards

anatak

 

 

How can I do this so I don't have to create a variable for rotate.inc and stylesheet.inc ?

 

 

Link to comment
https://forums.phpfreaks.com/topic/132553-include-with-a-path-variable/
Share on other sites

Two ways at least:

include $_SESSION['path']."rotate.inc";

 

include "{$_SESSION['path']}rotate.inc";

 

Also make sure, that you've checked the path variable. It's potentially vulnerable for XSS attack.

 

One way to check would be using the file_exists. If the file exists, chances are you are not getting XSS attacked. If it does not, you probably are.

 

 

Hey premiso and Mchl,

 

Thank you for the answers and the hint.

I need this session path variable because of the file structure.

 

/dir function

  /rotate.inc

/dir public_html (webroot)

  /dir www (pc version of site)

      index_mobile.php

  /dir mobile (mobile version of site)

  index.php (require to index_public.php)

  /image (dir with all the graphic files and images

/index_www.php

/index_mobile.php

 

after reading the php security tutorial I wanted to stop outside file access.

 

I want to be able to use the functions in dir function with the mobile and the pc version (I don't want to maintain the functions separatly) and I also wanted to be able to use 1 folder for all the image files.

 

to check against XSS attacks would something like this work ?

 

if file_exists($_SESSION['path']."rotate.inc"){include $_SESSION['path']."rotate.inc";}

 

thank you

anatak

 

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.