Extremely Simple PHP code needed! Help!!

Indiigo007

Junior Member
Joined
Nov 11, 2009
Messages
189
Reaction score
191
I am using Content Lock Pro and want to use PHP to change an image on the page once the page is unlocked. On 'index.html', once unlocked, the content locker will redirect to 'index.html/?=trigger_text' and i want 'trigger_text' to cause an image to be replaced (through css class or ID) with another image (that says 'page unlocked'). Can anyone tell me what php code I would need on index.html to accomplish this?

Thanks and I will +rep generously for any any help :)
 
1. You will need to rename index.html to index.php (otherwise you php code won't run).

2. Let's say you want to call index.php?trigger=text and "text" will cause your image container (let's say it's a div) to have a different css class.

Your page should contain this at the top :

PHP:
<?php
// Only run this code if "trigger" is passed
if (isset($_GET['trigger'])) {

   $trigger = $_GET['trigger'];

   switch ($trigger) {
      case "text1":
         $id = "id1"; break;
      case "text2":
         $id = "id2"; break;
   }  

}
?>

You can add as many "case" as you need.

Then where you want your id to be hooked to the div container :

PHP:
<div id="<?php echo $id; ?>"></div>

And there you go !

With the above code, calling index.php?trigger=text1, your div will have "id1" as id. If you call index.php?trigger=text2, your div will have "id2" as id.
Now you just need to copy/paste this code and edit it according to your specific need :)

EDIT: damn the php code highlight is so hard on the eyes :s
 
You may be able to simplify this a bit.

Example url suffix:
Code:
?triggered

PHP:
<?php if(isset($_GET['triggered'])):?>

        <img src="lockedimagesrc" />
<?php else:?>

        <img src="unlockedimagesrc" />
<?php endif; ?>

This determines if the triggered hash exists, and if it does it shows img a, else it shows img b. The beauty of it is, you don't have to set a value to the GET, all you have to do is have it as 'triggered' or whatever else you fancy :)

EDIT: Also, if the code is nested within HTML, the PHP 'if' tags with the colon are a bit easier to read and keep track of.
 
Last edited:
1. You will need to rename index.html to index.php (otherwise you php code won't run).

2. Let's say you want to call index.php?trigger=text and "text" will cause your image container (let's say it's a div) to have a different css class.

Your page should contain this at the top :

PHP:
<?php
// Only run this code if "trigger" is passed
if (isset($_GET['trigger'])) {

   $trigger = $_GET['trigger'];

   switch ($trigger) {
      case "text1":
         $id = "id1"; break;
      case "text2":
         $id = "id2"; break;
   }  

}
?>

You can add as many "case" as you need.

Then where you want your id to be hooked to the div container :

PHP:
<div id="<?php echo $id; ?>"></div>

And there you go !

With the above code, calling index.php?trigger=text1, your div will have "id1" as id. If you call index.php?trigger=text2, your div will have "id2" as id.
Now you just need to copy/paste this code and edit it according to your specific need :)

EDIT: damn the php code highlight is so hard on the eyes :s

He said, index.html/?=trigger_text in the question. Not index.html/?trigger=trigger_text
 
He said, index.html/?=trigger_text in the question. Not index.html/?trigger=trigger_text
Aside from both files/querystrings you just mentioned being invalid, doing ?=trigger_text does not pass it to the $_GET querystring array. It has to be something like ?a=trigger, i.e. a variable name and a value. If you don't know what you're talking about you shouldn't try to correct others.

Also, to the OP, rather than redirecting back to index with the GET parameter in the URL, you should just run a javascript function to do what you need. This will make the process more instantaneous, plus will close up the loophole that will occur by using your mentioned method. i.e. if someone goes to index.html?trigger directly, then they can bypass the content locker.

A pseudocode of what you should do in javascript is:
Code:
function checkLocker:
  if offer is completed:
    myImage = image element;
    change myImage source image;
    hide the locker;
  else:
    do nothing;
end function;

set up locker;

set interval to run checkLocker every x milliseconds;
 
Last edited:
He said, index.html/?=trigger_text in the question. Not index.html/?trigger=trigger_text

Still, my post actually gave OP a working and satisfying solution (I've got some +rep from him for this post, which confirms this helped).

Now tell me how you are contributing with such a post and attitude ?

Here's a piece of advice for you: go back to DP.
 
Aside from both files/querystrings you just mentioned being invalid, doing ?=trigger_text does not pass it to the $_GET querystring array. It has to be something like ?a=trigger, i.e. a variable name and a value. If you don't know what you're talking about you shouldn't try to correct others.

Heh, you don't need to set a variable to pass the array to the $_GET (tested before posting).

I agree that writing a simple JS function is probably a better solution, however OP asked for PHP ;)
 
Back
Top