Is it possible to give the user a link that toggles a section of my PHP code on or off, or changes the code itself? For instance, say I have a line of code that says "if(++$count >= 5)," and I want it to change to "if(++$count >= 10)" when the user clicks a link. Is this possible? If I wanted to, could I just have it omit "if(++$count >= 5)" from the code when the user clicks the link? Thanks! -Peter ::EDIT:: NOTE: For those of you wondering, I ended up sticking with my original setup: two nearly identical files, different only for those lines of code. Thanks to all who replied.
You could do something like site.php?value=5 And in the php code you do "if(++$count >= $value)" If you want to do this without a page refresh you can do it with AJAX
Smaaz is right, except he's assuming register globals is on (a no no!) if (++$count >= $_GET['value']) { //blah } PHP:
The only way you could do that would be to use a variable. Say instead of the 5 or the 10 you used a variable called limit. If it's set in a GET parameter use that value, otherwise use 5. Something like: $limit = ( isset( $_GET['limit'] ) ? $_GET['limit'] : 5 ); Then on the link you want the user to click, just add the GET parameter (?limit=10).
What would the link code be? Also, how secure is this? (Thanks for all the active replies this early in the morning!)
What I actually want to do is toggle a few lines of code. The way I have it set up now, a user can click a link and it goes to an identical PHP file, minus the lines I want to omit. How can I toggle the inclusion of these lines using one file?
Not quite sure what you want done.. but you could do something along the lines of: if (isset($_GET['blah'])) { //do something } else { //do something else } PHP: Instead of linking to the identical file, just link to file.php?blah and it'll execute the first set of code, otherwise it'll execute the second. I can provide a better example if you explain it further..
Anyone can just look at your source code and supply their own number via the URL. Not safe exactly... You might want to try session id's if looking for something safer. Bye
Or let the link update a DB table for that user which sets the variable there. $_GET is unsafe, someone could set it to 10000000000000 and stall your server.
Something like this is posted all over, it was also a site-specific solution which others won't benefit from.
Correct, CodyRo helped me with it, and after toying around with a few options, we decided that the best way was what I have set up now (and had originally). Thanks for all your help!
Wowzers . . . once again someone works DP members so hard for solutions to problems in public forums. Peons reply, bury the solution, and get dodgy when asked about it. I thought the whole point of DP was a place for people to come and share problems and solutions, and ideas for the mutual benefit of all participants. Forums, like open source, rely on people to share their ideas as the best answers to questions evolve. I have seen so many examples around DP of people solving issues via PM and then posting the answer so all could benefit. I applaud those people because they help us all find new approaches to what are, in truth, problems each of us will most likely encounter in the future.
I told you exactly how I solved it. Due to potential security vulnerabilities, I didn't release tons of info about the script (I'm still learning PHP, so I don't want to expose some fatal mistake to a hacker). I tried my best to share what I came up with, which is what I had originally: two files, one with the extra code.
Ahem, as stated it was the nature of the code it was done via PM, if you look at anything else I've done (or even previously in this topic) you'll see theres nothing "dodgy". But I love you anyway.
First, I want you to know that I don't have problems if you post the code, or not. It's your script, it's your decision. But just so you know, the way to "prevent hacking" is not to "hide" your code, but to "improve" it... Let's finish this topic here. Bye