PDA

View Full Version : Passing variables between webpages



toxinfree
11-28-2007, 07:27 AM
Hi all,

Hope someone can help me out here. :confused:

I have a few video files that I want to include in my website. I want to set up a link to each one so my visitors can view select whichever video they want and then view it on its own page.

However, the coding for each video page will the same, save for the name of the video filename. So rather than have a separate html page for each video I want to set up a single html page (called video.htm) for the job and then call just pass the name of the video file into it. For example:


video.htm?VideoName=video1.mov

I'm assuming that's how you pass variables into a webpage (I seem to remember reading something like that somewhere else). But then what do I do? How do I call the VideoName variable in the new html page?

Any ideas please?

sjlplat
11-28-2007, 09:05 AM
I just did this with YouTube and Google videos using PHP. Here's a working code you can use. This will open the videos in popup windows that fit the physical dimensions of the video.

Create a separate PHP file named video.php and place the following code in it. Edit the parameters that are in red:


<?php
$url = 'http://www.yoursite.com/path/to/video/directory/';
$file = $_REQUEST['file'];
$vid = $url . $file;
?>

<html>
<head>
<title><?php echo $file; ?></title>
</head>
<body>

<embed src="<?php echo $vid; ?>" width="200" height="240" autoplay="true">

</body>
</html>

Call it with:


<a style="cursor:pointer" onClick=window.open("video.php?file=filename.mov","view","width=200,height=240,top=0,left=0,resizable=0,scro llbars=0,titlebar=0,toolbar=0,menubar=0,status=0,d irectories=0,personalbar=0")>Name of Video</a>

Or if you don't want a popup window, call it with:


<a href="video.php?file=filename.mov">Name of Video</a>

toxinfree
11-28-2007, 04:38 PM
Thanks sjlplat for your kind assistance. The coding looks good and I think I've got a grasp of what you mean and how it works.

However, the <embed> bit doesn't quite work. I need to download some plugins from Apple's server in order to get a .mov file to run on QuickTime. Thus I have previously used the following:

<object codebase=http://www.apple.com/qtactivex/qtplugin.cab height=255 width=320 border=1px bordercolor=#000000> <param name=src value=videofilename.mov /> <param name=autoplay value=true /> <param name=controller value=true />
<embed height=255 pluginspage=http://www.apple.com/quicktime/download/ src=videofilename.mov type=video/quicktime width=320 controller=true autoplay=true>
</embed>
</object>

This works a treat for a normal webpage. However, as I am trying to introduce a variable into the mix this needs a little adjustment. I tried a mix of the above plus your coding. Thus my video.php file looks like this:

<?php
$url = 'http://www.toxinfreebodycare.com/';
$file = $_REQUEST['file'];
$vid = $url . $file;
?>

<html>
<head>
<title><?php echo $file; ?></title>
</head>
<body>

<object codebase=http://www.apple.com/qtactivex/qtplugin.cab height=255 width=320 border=1px bordercolor=#000000> <param name=src value="<?php echo $vid; ?>" /> <param name=autoplay value=true /> <param name=controller value=true />
<embed height=255 pluginspage=http://www.apple.com/quicktime/download/ src="<?php echo $vid; ?>" type=video/quicktime width=320 controller=true autoplay=true>
</embed>
</object>

</body>
</html>

And I call it thus:

<html>
<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Videos to watch</title>
</head>
<body>
<p><a href="video.php?file=video1.mov">Video 1</a></p>
<p><a href="video.php?file=video2.mov">Video 2</a></p>
<p><a href="video.php?file=video3.mov">Video 3</a></p>
</body>
</html>

That didn't quite work either. I don't know whether I'm being really dim & missing the point. Or if I've left something out. I'd appreciate your advice on this though.

Many thanks.

toxinfree
11-28-2007, 06:09 PM
Please ignore my previous reply. After much pawing over the problem I noticed that I'd spelled the filenames wrong in the html file that calls the video.php file.

So no I don't need to download any plugins after all.

I guess I look like a complete twonk now! Still, you live & learn, huh? At least it works now.

Anyway, thanks a load for all your advice. This'll save me having to duplicate webpages, for the sake of just changing the filename. :)

griff671
11-28-2007, 07:47 PM
Well, if that makes you a twonk, then we're all twonks, heh heh! I'll defy anyone who claims they haven't goofed along the way!

Thanks for posting your find, it will help someone else down the road!

sjlplat
11-29-2007, 08:08 AM
This'll save me having to duplicate webpages, for the sake of just changing the filename. :)

If you have a lot of files, I can write a script that will collect all the files from a dedicated directory and build a table for you. Might save you some time creating file lists.


Well, if that makes you a twonk, then we're all twonks, heh heh! I'll defy anyone who claims they haven't goofed along the way!

Thanks for posting your find, it will help someone else down the road!

Believe it or not, I found a few minor variable mistakes I made when I posted that code. I had to edit things a couple times before I got it right. :eek: :D

griff671
11-29-2007, 09:49 AM
. . .Believe it or not, I found a few minor variable mistakes I made when I posted that code. I had to edit things a couple times before I got it right. :eek: :D
Na-a-a-h, I'm not believin' it! ;) :D

toxinfree
11-29-2007, 01:39 PM
If you have a lot of files, I can write a script that will collect all the files from a dedicated directory and build a table for you. Might save you some time creating file lists.

Thanks sjlplat, that would be very kind.

I must admit, I haven't yet started looking at php. I'm just getting to grips with javascript. And even with that I'm only a novice. I have programming experience in other languages so I can get an idea of what a javascript or php script is doing, but only I'm only able to write simple javascripts at the mo. Although having said that, there's plenty of free scripts on the net.

I'd like to teach myself php. If you or anyone else can recommend any "Teach Yourself PHP" books or website, I'd be grateful.

sjlplat
11-30-2007, 08:41 AM
I learned PHP on my own from http://www.tizag.com - I'm sure you can learn quick if you're already an experienced programmer. I was writing open-source scripts and publishing them on Hotscripts.com in about 6 weeks.

CafeenMan
11-30-2007, 09:24 AM
I wish I could learn php quick. I can write several languages but I use VB the most. I would use ASP but when I was searching for hosting years ago the cost wasn't worth it.

So I tried php and it made absolutely no sense to me at all. commas and colons everywhere and they mean different things in different contexts. Several times I spent more than an hour debugging one line of code because I used a comma, period or apostrophe wrong. I never did figure it out but I got my stuff working eventually.

It may just be me but I hate php. I use it as little as possible and a lot of stuff I could write easily in VB I don't even attempt in php because I can't afford to replace monitors after I throw things through them. :)

All that said, I'm pretty sure my opinion is pretty much the minority among php users.

shadmego
11-30-2007, 09:33 AM
CafeenMan, check this site out. It lays out VERY basic information about php. I used it and though I don't consider myself a programmer, I can read php now and "sort of" understand what's going on.

http://www.w3schools.com/php

~regards

sjlplat
11-30-2007, 10:06 AM
I wish I could learn php quick. I can write several languages but I use VB the most. I would use ASP but when I was searching for hosting years ago the cost wasn't worth it.

So I tried php and it made absolutely no sense to me at all. commas and colons everywhere and they mean different things in different contexts. Several times I spent more than an hour debugging one line of code because I used a comma, period or apostrophe wrong. I never did figure it out but I got my stuff working eventually.

It may just be me but I hate php. I use it as little as possible and a lot of stuff I could write easily in VB I don't even attempt in php because I can't afford to replace monitors after I throw things through them. :)

All that said, I'm pretty sure my opinion is pretty much the minority among php users.

Something that helped me a lot was a program called Notepad++. It has syntax highlighting, which helps me understand those obscure commas, periods, and apostrophes. It's like night and day once you take advantage of syntax highlighting.

CafeenMan
11-30-2007, 11:20 AM
The main problem I have with php is when I'm using php to generate html. I've visited the link shadmego provides several times.

It's stuff like this that drives me nuts because the html already has (or hasn't) quotes around it and then I'm trying to use php to echo it to the form.


if ($dYear == $CurrentYear)
{
$count = $CurrentYear - 1;
While ($count >= $StartYear)
{
echo "<li><p style=\"margin-bottom: 0\">";
echo "<a href=\"site_feedback.php?dYear=$count\">Feedback from $count</a></p></li>";
$count--;
}
}
else
{
echo "<li><p style=\"margin-bottom: 0\">";
echo "<a href=\"site_feedback.php\">This Year's Feedback</a></p></li>";
$count = $CurrentYear - 1;
While ($count >= $StartYear)
{
if ($count != $dYear)
{
echo "<li><p style=\"margin-bottom: 0\">";
echo "<a href=\"site_feedback.php?dYear=$count\">Feedback from $count</a></p></li>";
}
$count--;
}
}
</script>

shadmego
11-30-2007, 04:32 PM
I was trying to learn about strings in php a while back and I came up with this page (http://www.4christministry.org/php/escape.php). I can't remember where I was going with it, but feel free to look. It might help you out a bit.

~regards

toxinfree
01-01-2008, 01:50 PM
Hi sjlplat,

Many thanks for all your help and advise. Just thought you might like to see the end product. So here it is:

www.2ndincomeplus.co.uk (http://www.2ndincomeplus.co.uk)

If you go to the navigation bar at the bottom of the page and look at "Success Stories". That is where I have used your technique. It has saved my a lot of time and effort. Once again, many thanks. :)

ToxinFree (http://www.toxinfreebodycare.com)