-2

I'm attempting to make a different animation depending on from where the user navigated from, but this isn't working. Thanks!

    <?php 
    $ref =$_SERVER['REQUEST_URI'];      
?>

<script type="text/javascript">
    if(<?php $ref; ?>) == 'http://livvedesign.com/content/philosophy.php/'){
        $('#wrapper1').css('left','-150vw');
        $('#wrapper1').delay(500).animate({left:'0vw', opacity:1}, 800);
    };
    if(<?php $ref;?> == 'http://livvedesign.com/content/meet.php/'){
        $('#wrapper1').css('left','150vw');
        $('#wrapper1').delay(500).animate({left:'0vw', opacity:1}, 800);
    };
    if(<?php $ref;?> == 'http://livvedesign.com/content/contact2.php/'){
        $('#wrapper1').css('top','250vh');
        $('#wrapper1').delay(500).animate({top:'0vh', opacity:1}, 800);
    };
     if(<?php echo $ref;?> == 'http://livvedesign.com/content/projects.php'){
        $('#wrapper1').css('top','250vh');
        $('#wrapper1').delay(500).animate({top:'0vh', opacity:1}, 800);
    };
    if(<?php $ref ?> == "" || <?php $ref ?> == 'index.php') {$('#wrapper1').animate({opacity:1}, 700);};
        </script>
cgauss
  • 324
  • 3
  • 16
  • Why do some have `echo` and some don't? – Andrius Naruševičius Jul 23 '13 at 05:56
  • you cant use it like this, you need to use `echo` like this `if() ` – dreamweiver Jul 23 '13 at 05:58
  • Why would you throw all that javascript to the client? IMHO there are 2 better options (1) It seems the javascript could just be fixes, and inspect `window.location.href`, so zero PHP needed (2) If you _do_ want to use PHP, just use a switch in PHP itself (omit the protocol & domain for matching), and only echo out the javascript portion relevant for _that_ page. – Wrikken Jul 23 '13 at 06:06

3 Answers3

3

If you want to print the $ref variable you should do:

<?php echo $ref;?>

or the shortcut syntax if you have short open tags enabled:

<?=$ref?>

You will also need to put the string in quotes so each if statement should look something like:

if('<?=$ref?>' == 'http://livvedesign.com/content/philosophy.php/'){

You also have extra brackets in some lines like this:

if(<?php $ref; ?>) == 'http://livvedesign.com/content/philosophy.php/'){
                 ^ //This should not be here
Kara
  • 6,115
  • 16
  • 50
  • 57
0

Try to print_r/var_dump $_SERVER. You would see that $_SERVER['REQUEST_URI'] doesn't give you the data you expect. I guess you really meant to use $_SERVER['HTTP_REFERER'], and as a comment say you are missing some echoes.

Also when echoing $ref you should make sure to escape the data. It is easily altered by a potential attacker.

JimL
  • 2,501
  • 1
  • 19
  • 19
0

The REQUEST_URI which was given in order to access the page not referer

$ref = $_SERVER['REQUEST_URI']; 

echo $ref;

// Output
/content/philosophy.php/

Use referer:

$ref = $_SERVER['HTTP_REFERER']; 
Bora
  • 10,529
  • 5
  • 43
  • 73