0

I have a value in a php variable $thumb_path="images/Gallery1/thumbs/";. I need to change this value to $thumb_path="images/Gallery2/thumbs/"; when I am clicking on Gallery2 Link n my project. Is it possible to change a value in a PHP variable using JavaScript?

Or is there any other way to do this?

1
  • 1
    i do not think you are approaching your problem correctly. php is happening on the server side, however javascript is client-side (browser). perhaps if you provide background for your problem we can help direct you to the correct course of action Commented Mar 31, 2011 at 11:02

2 Answers 2

2

JS is a client side language, PHP is parsed on server, so you can't change the php file itself with js... BUT: :)

You can manage it with GET:

$thumb_path="images/Gallery".(($_GET['gallery'] && preg_match('/^[0-9]+$/', $_GET['gallery'])) ? $_GET['gallery'] : "1")."/thumbs/";

now you can call your link like this:

http://www.page.com/yourphpfile.php?gallery=2

This will open gallery 2.

If you dont set ?gallery gallery 1 will shown as default.

Sign up to request clarification or add additional context in comments.

1 Comment

you should check the GET var because of possible malicous code... for example do an intval() on it...
0

Since JavaScript is a client-, and PHP is a server-side language, obviously you can't.

You can use some AJAX if possible. If this is some kind of dynamic variable (you'll getting this data from a form), you can change it with JavaScript.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.