echo problem

Discussion in 'PHP' started by izlik, Aug 17, 2010.

  1. #1
    how can i make this work? :/


    $homepage = "/";
    $currentpage = $_SERVER['REQUEST_URI'];
    if($homepage==$currentpage) {
    echo '<meta HTTP-EQUIV="REFRESH" content="0; url=http://mypage.com/<? echo rand(1, 102); ?>">';
    }
    PHP:

     
    izlik, Aug 17, 2010 IP
  2. chandan123

    chandan123 Prominent Member

    Messages:
    11,586
    Likes Received:
    578
    Best Answers:
    0
    Trophy Points:
    360
    #2
    why echo needed in second place ? (as its already in php tag )
     
    chandan123, Aug 17, 2010 IP
  3. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #3
    it's there by misstake, but even if i remove it rhe resault is currently "http://mypage.com/%3C?%20rand(1,%20102);%20?%3E" when i go to my page the rand wont do a random number :/
     
    izlik, Aug 17, 2010 IP
  4. Narrator

    Narrator Active Member

    Messages:
    392
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    80
    #4
    No need to use echo twice:
    
    <?
    $homepage = "/";
    if($homepage==$_SERVER['REQUEST_URI']) {
    ?>
    <meta HTTP-EQUIV="REFRESH" content="0; url=http://mypage.com/<? echo rand(1, 102); ?>">
    <? } ?>
    
    PHP:
     
    Narrator, Aug 17, 2010 IP
  5. Aids

    Aids Peon

    Messages:
    195
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Narrator got it spot on.

    You used echo twice.
     
    Aids, Aug 17, 2010 IP