0

I'm coding a site so that I can watch YouTube without flash player.

index.html > [code]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Youtube4Tor</title>
</head>

<body>
<center>
<img src="http://twimgs.com/informationweek/byte/news/2012-August/YouTube-Logo.png" />
<h3>Watch YouTube Without Flash in Tor</h3>
<br />
<form action="play.php" method="post">
<table>
<tr>
<td>
Youtube URL:
</td>
<td>
<input type="text" name="video" /><br />
</td>
<td>
<p style="color: #F00">Type in the code after the url,<br /> eg. If the video URl is<br /> "https://www.youtube.com/watch?v=dqUdI4AIDF0",<br /> type in: dqUdI4AIDF0</p>
</td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" /></center></td>
</tr>
</table>
</form>
</center>
</body>
</html>

[/code]

I'm stuck on the PHP, you see, what I want it to do is to get what the user entered, and insert it here:

<iframe width="560" height="315" src="https://www.youtube.com/embed/**HERE** frameborder="0" allowfullscreen></iframe>

Any help is appreciated.

Aurora

4
  • 1
    you will get user input in "S_POST" global variable. Use: src="youtube.com/embed/<?php echo $_POST['video']?>" Commented Mar 8, 2014 at 12:05
  • You can't do thst unless you post form to self. You're better off imcluding play.php in index.html and passing a local variable. Commented Mar 8, 2014 at 12:39
  • Need to see what's inside play.php Commented Mar 8, 2014 at 14:45
  • This is what's in the play.php --> <center> <h2>Enjoy.</h2> <iframe width="630" height="354.375" src="youtube.com/embed/<?php echo $_POST['video']?>" frameborder="0" allowfullscreen></iframe> <p style="color:red;">Video not showing up? Did you follow the instructions?</p> </center> This is how I've done it: tor.youtubell.com Commented Mar 8, 2014 at 17:39

1 Answer 1

1

I don't know how you're planning on showing the iframe, but this works when placed inside the same page as the form: (Using action="" as the form's action).

<iframe width="560" height="315" src="https://www.youtube.com/embed/<?php if(isset($_POST['video']) && !empty($_POST['video']) ){ echo $_POST['video']; } ?>" frameborder="0" allowfullscreen></iframe>

Using:

<?php if(isset($_POST['video']) && !empty($_POST['video']) ){ echo $_POST['video']; } ?>

I would need to know how you're planning to show it, and what you have inside the play.php file.

Let me know if this works for you. If you have any questions, feel free to ask.


Using sessions

You can also use sessions which I tend to think would be a more flexible method.

Here is an example which has everything inside one page, but you could use the session variable pretty much anywhere outside that page, just as long as session_start(); is included, along with the session variable.

<?php
session_start();
$_SESSION['video'] = $_POST['video'];
// echo $_SESSION['video']; // for testing purposes only
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Youtube4Tor</title>
</head>

<body>

<center>
<img src="http://twimgs.com/informationweek/byte/news/2012-August/YouTube-Logo.png" />
<h3>Watch YouTube Without Flash in Tor</h3>
<br />
<form action="" method="post">
<table>
<tr>
<td>
Youtube URL:
</td>
<td>
<input type="text" name="video" /><br />
</td>
<td>
<p style="color: #F00">Type in the code after the url,<br /> eg. If the video URl is<br /> "https://www.youtube.com/watch?v=dqUdI4AIDF0",<br /> type in: dqUdI4AIDF0</p>
</td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" /></center></td>
</tr>
</table>
</form>

<iframe width="560" height="315" src="https://www.youtube.com/embed/<?php if(isset($_SESSION['video']) && !empty($_SESSION['video']) ){ echo $_SESSION['video']; } ?>" frameborder="0" allowfullscreen></iframe>
</center>
</body>
</html>

Page 2 test

The same video showed up on another page that I created (I didn't have to re-enter the YouTube ID), using the following:

<?php
session_start();
// echo $_SESSION['video']; // just to echo the video ID
?>

<iframe width="560" height="315" src="https://www.youtube.com/embed/<?php if(isset($_SESSION['video']) && !empty($_SESSION['video']) ){ echo $_SESSION['video']; } ?>" frameborder="0" allowfullscreen></iframe>

Here is another method using sessions: (A better method, I think)

<?php
session_start();

$video = $_POST['video'] = $_SESSION['video'];
echo $video; // echo video ID number
echo "<hr>";
echo $_SESSION['video']; // echo video ID number test
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Youtube4Tor</title>
</head>

<body>
<center>
<img src="http://twimgs.com/informationweek/byte/news/2012-August/YouTube-Logo.png" />

<h3>Watch YouTube Without Flash in Tor</h3>
<br />
<form action="" method="post">
<table>
<tr>
<td>
Youtube URL:
</td>
<td>
<input type="text" name="video" /><br />
</td>
<td>
<p style="color: #F00">Type in the code after the url,<br /> eg. If the video URl is<br /> "https://www.youtube.com/watch?v=dqUdI4AIDF0",<br /> type in: dqUdI4AIDF0</p>
</td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" /></center></td>
</tr>
</table>
</form>

</center>
</body>
</html>

Then if you were to create another page called see_video.php for example, you would see the same video on that page without re-entering the YouTube ID number:

<?php
session_start();
if(isset($_SESSION['video']) && !empty($_SESSION['video']))
    {
    echo $_SESSION['video']; // echo video ID number
    }
else { echo "Sorry, no video chosen."; }
?>

<iframe width="560" height="315" src="https://www.youtube.com/embed/<?php if(isset($_SESSION['video']) && !empty($_SESSION['video']) ){ echo $_SESSION['video']; } ?>" frameborder="0" allowfullscreen></iframe>
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the feedback. This is how I have done it. tor.youtubell.com This is what's in the play.php ---> <center> <h2>Enjoy.</h2> <iframe width="630" height="354.375" src="youtube.com/embed/<?php echo $_POST['video']?>" frameborder="0" allowfullscreen></iframe> <p style="color:red;">Video not showing up? Did you follow the instructions?</p> </center>
You're welcome. I will be happy to help when I get back, I have to leave now, but will contact you when I return. @Aurora
Hi. Works fine when I tried it on your site. @Aurora
If you feel my answer fixed your problem, click the White checkmark till it turns Green to accept my answer. @Aurora

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.