1

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

2
  • On a side note, depending on when you're setting your PHP variable you might be having a server/client side scripting issue, meaning you might need use some JavaScript (probably jQuery) to do a AJAX script to change the src attribute. Commented Feb 15, 2013 at 19:59
  • 1
    what is happening and what are you expecting it to do? Commented Feb 15, 2013 at 20:01

4 Answers 4

1

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";
}

?>
Sign up to request clarification or add additional context in comments.

4 Comments

Yes the code is not written well but the If/Else is not the 'issue'. You do not need brackets if one line follows. Yes it's a good practice, but not needed.
With out the braces the if will only execute the immidately after it ignoring the else statement. At least thats my understanding.
Yes the if statement will execute the next statement, but the else is still considered even without braces. Example
See what you're saying. Still makes my eyes hurt reading it :(
1

Need semicolon:

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

Comments

0

Use empty(), like this:

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

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

Comments

0
<?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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.