Forum Moderators: coopster

Message Too Old, No Replies

passing in variables to a php form ?

How to pass in dir name?

         

rocsw

2:41 am on Jul 22, 2009 (gmt 0)

10+ Year Member



I have something like this in several index.html files in various subdirectories on my website ...

<a href="http://www.mywebsite.com/some-sub-dir-name/a-php-form.php" target="_blank">Click to pop up a form to play with.</a>

I’d really like to be able to ‘pass in’ (I guess that’s the term/phrase to use) a variable (say ‘subdir’) which would be the name of the subdirectory the user was in when clicking that link.

So, if someone were viewing [mywebsite.com...]

And they clicked on the link, it would be as if the link was really like this ...

<a href="http://www.mywebsite.com/some-sub-dir-name/a-php-form.php?subdir=one-of-my-sub-dirs" target="_blank">Click to pop up a form to play with.</a>

Is there a way to do this (I want to avoid having to create custom links in every single index.html file) ?

Thanks,

Newbie in Newbiechester

andrewsmd

1:40 pm on Jul 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you sites are straight html, then you would have to use JavaScript. If they are php and you just typed index.html then google how to get the current url with php. You could then use a substring of that url to get the sub directory. Post back if you need more explanation.

mattclayb

1:49 pm on Jul 22, 2009 (gmt 0)

10+ Year Member



So am I right in thinking you want to get the name of the directory that the user is accessing the page from? ie -

[yourwebsite.com...] ?

If that's the case you could do something like this bu tyou will need to change the index.html to php.

<?
//get the document path relative to the web root directory
$docpath = $_SERVER['PHP_SELF'];

//split the document root by each "/"
//and store each name as variables within an array
$docpath = explode("/",$docpath);

//this is assuming the directory name you want is the
//first subdirectory within your web directory.
//change $docpath[0]; to $docpath[1]; if you want the next directory down
$directory_name = $docpath[0];

?>