link shortener

Discussion in 'PHP' started by sponebob119, May 29, 2012.

  1. #1
    Hey guy,
    I'm new to php and this forum too... i'm currently working with link shortener scripts,
    it redirecting using php header function but I don't want to redirect i want to show a banner with original website :cool: (like adfly)

    [​IMG]
    This is the original code :
    <?php    if($_GET['id']){        require("mysql.php"); // to establish a connection to the db        $id = addslashes($_GET['id']);        $getUrl = mysql_query("select url from urls where id = $id"); // check if the id exists in the db        if(mysql_num_rows($getUrl)==1){ // if so we redirect using the header function            $url = mysql_fetch_array($getUrl);            header("location:".$url['url']);         } else {            echo "Error : invalid hash";        }    } else {        echo "Error : no hash";    }?>
    PHP:
    how ever I edited original code and put a iframe to display original website with banner but the thing is it's not working, so please some one can help me with this code,

    My edited code
    <html><head>
    <style type="text/css"><!--body {    margin-left: 0px;    margin-top: 0px;    margin-right: 0px;    margin-bottom: 0px;}--></style></head><body><table width="100%" height="10%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFF00">  <tr>    <td>&nbsp;</td>  </tr></table><?php    if($_GET['id']){        require("mysql.php"); // to establish a connection to the db        $id = addslashes($_GET['id']);        $getUrl = mysql_query("select url from urls where id = $id"); // check if the id exists in the db        if(mysql_num_rows($getUrl)==1){ // if so we redirect using the header function            $url = mysql_fetch_array($getUrl);            $lk= $row[0] ;echo  "<iframe src=\"{$lk}\"frameborder=\"0\" height=\"90%\" scrolling=\"auto\" width=\"100%\"></iframe>";         } else {            echo "Error : invalid hash";        }    } else {        echo "Error : no hash";    }?>
    </body></html>
    PHP:
    Hope you can understand what i'm trying to saying and sorry for my bad English ! also guy I really love this script how works and I don't wanna move to a open source thing, just want to edit this code to work as I wish :(
     
    Solved! View solution.
    sponebob119, May 29, 2012 IP
  2. Grit.

    Grit. Well-Known Member

    Messages:
    1,424
    Likes Received:
    22
    Best Answers:
    1
    Trophy Points:
    110
    #2
    So when you say it's not working, what is it actually displaying?!?
    Do you see your banner/logo and the iframe isn't working, or is it all not working?

    If it's just the iframe, I don't see why you didn't use $url['url']) for the iframe source, and it might be good practice to use concatenation.
     
    Grit., May 29, 2012 IP
  3. sponebob119

    sponebob119 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It's displaying error,
     
    sponebob119, May 29, 2012 IP
  4. sponebob119

    sponebob119 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ok now I edited code like this (iframe code)
    echo  "<iframe src=\$url['url']\ frameborder=\"0\" height=\"90%\" scrolling=\"auto\" width=\"100%\"></iframe>"; 
    Code (markup):
    now I can see my banner hanging up there but still iframe is not working,it's getting a error like this
     
    sponebob119, May 29, 2012 IP
  5. #5
    You have to escape the variable or append it.

    echo  "<iframe src=\"{$url['url']}\" frameborder=\"0\" height=\"90%\" scrolling=\"auto\" width=\"100%\"></iframe>";
    PHP:
    or,
    echo  "<iframe src=\"" . $url['url'] . "\" frameborder=\"0\" height=\"90%\" scrolling=\"auto\" width=\"100%\"></iframe>";
    PHP:
     
    akhileshbc, May 29, 2012 IP
  6. sponebob119

    sponebob119 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Your my hero.......... Thank you friend !! Thank you every one helped me out here !!!
     
    sponebob119, May 30, 2012 IP
  7. akhileshbc

    akhileshbc Active Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #7
    Glad to know that it helped you.

    Good luck :)
     
    akhileshbc, May 30, 2012 IP