user2012141
user2012141

Reputation: 23

HTML Iframe get src with php

I have an webpage where I want to have another html page displayed. I used iframes. The page gets to know what to load is via the get procedure. But there is an fault in this coding I think...

            <iframe src="
            <?
            $file       = ($_GET['ti'])

            if ($title = '')
                echo "information.html";
                else echo "$file";
            ?>
            "></iframe>

The url the page would recieve looks like this: http://www.website.com/reference.html?ti=unlimited.html

Upvotes: 1

Views: 4213

Answers (4)

Iron3eagle
Iron3eagle

Reputation: 1077

http://www.w3schools.com/php/php_if_else.asp

It's your if / else syntax and over all php code. It's not very well written.

<?php

$file = $_GET['ti'];

if ($title = '') {
     echo "information.html";
} else { 
     echo "$file";
}

?>

Upvotes: 1

Green Black
Green Black

Reputation: 5084

<?php
    $possible = array("information.html", "home.html", "test.html");
    $file = isset($_GET['ti']) && 
            in_array($_GET['ti'], $possible)? $_GET['ti'] : "information.html";
?>
<iframe src="<?php echo $file;?>"></iframe>

Upvotes: 0

Julien
Julien

Reputation: 1980

Use empty(), like this:

    <iframe src="
    <?
    $file       = ($_GET['ti'])

    if (empty($title))
        echo "information.html";
        else echo $file;
    ?>
    "></iframe>

Upvotes: 0

fedorqui
fedorqui

Reputation: 289775

Need semicolon:

        $file       = ($_GET['ti']);

Upvotes: 1

Related Questions