HTML Iframe get src with php - 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

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

Need semicolon:
$file = ($_GET['ti']);

Use empty(), like this:
<iframe src="
<?
$file = ($_GET['ti'])
if (empty($title))
echo "information.html";
else echo $file;
?>
"></iframe>

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

Related

POST variable - XHTTP, PHP [duplicate]

I have an URL which is to be used for getting post data after pasting and pressing enter in the browser.
My link is :
http://vtrails.us/mixtape-builder/?song_urls=http://vtrails.us/wp-content/uploads/2015/12/mpthreetest.mp3&song_artist=ganja
<?php
if(isset($_POST['song_urls']) && !empty($_POST['song_urls'])){
$song_url = $_POST['song_urls'];
$song_artist = $_POST['song_artist'];
}
echo $song_url;
echo $song_artist;
?>
But i am not getting any of them.So what can i do now?
If you use $_GET instead of $_POST you will get desired result:
Here is the code
<?php
if(isset($_POST['song_urls']) && !empty($_POST['song_urls'])){
$song_url = $_POST['song_urls'];
$song_artist = $_POST['song_artist'];
}
echo $song_url;
echo $song_artist;
?>
Its $_GET, not $_POST. Do this:
<?php
if(isset($_GET['song_urls']) && !empty($_GET['song_urls'])){
$song_url = $_GET['song_urls'];
$song_artist = $_GET['song_artist'];
}
echo $song_url;
echo $song_artist;
?>

Dynamic variable in PHP [GET]

I'm trying to use the php get. everthing is working find exept the include page.
it's adding 1 at the end of include content
any ide how do i ride that?
example:
I love norway
I love norway1
Code:
<?php
if($_GET['boy'] == 'zabi') $zabkas = 'it is Zabi';
if($_GET['girl'] == 'veronka') $verona = 'It is veronka';
if($_GET['place'] == 'norway') $norge = include('norway.php');
?>
<?php echo $zabkas ?>
<?php echo $verona ?>
<?php echo $norge ?>
We should use file_get_contents, instead of include.
$norge = file_get_contents("norway.php");
Use the output buffer functions to capture the output from the included script.
<?php
if($_GET['boy'] == 'zabi') $zabkas = 'it is Zabi';
if($_GET['girl'] == 'veronka') $verona = 'It is veronka';
if($_GET['place'] == 'norway') {
ob_start();
include("norway.php");
$norge = ob_get_clean();
}
?>
<?php echo $zabkas ?>
<?php echo $verona ?>
<?php echo $norge ?>

Php post method not getting data from url

I have an URL which is to be used for getting post data after pasting and pressing enter in the browser.
My link is :
http://vtrails.us/mixtape-builder/?song_urls=http://vtrails.us/wp-content/uploads/2015/12/mpthreetest.mp3&song_artist=ganja
<?php
if(isset($_POST['song_urls']) && !empty($_POST['song_urls'])){
$song_url = $_POST['song_urls'];
$song_artist = $_POST['song_artist'];
}
echo $song_url;
echo $song_artist;
?>
But i am not getting any of them.So what can i do now?
If you use $_GET instead of $_POST you will get desired result:
Here is the code
<?php
if(isset($_POST['song_urls']) && !empty($_POST['song_urls'])){
$song_url = $_POST['song_urls'];
$song_artist = $_POST['song_artist'];
}
echo $song_url;
echo $song_artist;
?>
Its $_GET, not $_POST. Do this:
<?php
if(isset($_GET['song_urls']) && !empty($_GET['song_urls'])){
$song_url = $_GET['song_urls'];
$song_artist = $_GET['song_artist'];
}
echo $song_url;
echo $song_artist;
?>

How to pass an URL to a <a href="">

I'm still new to php and I've made a script that checks the language of the website and if it's English set's the button link to an english page and else to another page.
Here goes:
<?php
$link1 = "http://www.uvt.ro/ro/accesibilitate/";
$link2 = "http://www.uvt.ro/en/accesibilitate/";
$url = "";
if($_SESSION["lang"]->lang!="ro"){
$url = $link2;
}
else {
$url = $link1;
}
?>
Button
It's supposed to be simple, I don't know why it doesn't work.
You'd echo the $url like so:
<?php
$link1 = "http://www.uvt.ro/ro/accesibilitate/";
$link2 = "http://www.uvt.ro/en/accesibilitate/";
$url = "";
if ($_SESSION["lang"]->lang != "ro") {
$url = $link2;
}
else {
$url = $link1;
}
?>
Button
You can condense the code to this using the ternary operator:
<?php
$link1 = "http://www.uvt.ro/ro/accesibilitate/";
$link2 = "http://www.uvt.ro/en/accesibilitate/";
$url = ($_SESSION["lang"]->lang != "ro") ? $link2 : $link1;
?>
Button
You have to echo $url in tag.
Button
Button
replace with:
Button
OR
Button
you can try this one:
See the page
<?php
$test = $_GET['p'];
?>
Test
or
Try like
HTML in PHP :
echo "<a href='".$link_address."'>Link</a>";
Or even you can try like
echo "<a href='$link_address'>Link</a>";
Or you can use PHP in HTML like
PHP in HTML :
Link

If variable is link, echo link

I having issues getting a function to echo, where $lightbox_link1 = get_custom_field('lightbox_link1'). I'm fairly new to PHP.
Below is the defining function:
// Check for a lightbox link, if it exists, use that as the value.
// If it doesn't, use the featured image URL from above.
if(get_custom_field('lightbox_link1')) {
$lightbox_link1 = get_custom_field('lightbox_link1');
} else {
$lightbox_link1 = $image_full[0];
}
Echo Function:
<?php if ($lightbox_link1 = get_custom_field('lightbox_link1')) {
echo '';
} ?>
<?php if ($lightbox_link1 = get_custom_field('lightbox_link1')) {
should be
<?php if ($lightbox_link1 == get_custom_field('lightbox_link1')) {
= is used for assignment
== is used for comparison
=== is used for typesafe comparison
also you can't declare <?php ... ?> inside another <?php ... ?>
to get something like <?php ... <?php ... ?> ... ?>
take a look at what you did up to here:
<?php if ($lightbox_link1 = get_custom_field('lightbox_link1')) {
echo '<a href="<?php
Instead, using doublequotes in your echo statement will allow for the php variables inside to be parsed, so you could just do
echo "<a href='{$lightbox_link1}' data-rel='prettyPhoto[{$post_slug}]'></a>";
to get
<?php if ($lightbox_link1 == get_custom_field('lightbox_link1')) {
echo "<a href='{$lightbox_link1}' data-rel='prettyPhoto[{$post_slug}]'></a>";
} ?>

Categories