Page 1 of 1

ASP to PHP

Posted: Mon Jun 19, 2006 5:52 pm
by dakev
I apologize in advanced if this topic is covered elsewhere. I looked but couldn't find anyhing.

I've switched hosts from a windows box to a Linux box. ASP was simple enough. I'm assuming PHP is also fairly simple, but I have a syntax question.

Here's what I need to know.

How do I write this statement in PHP.

Code: Select all

http://www.dakev.com/qtdisplay.asp?movie=x.mov&title=x
I imagine it would be something like this...

Code: Select all

http://www.dakev.com/qtdisplay.php?movie=<?php echo=$x.mov; ?>&title=<?php echo=$x; ?>;
I'm curious about the andpersan sign between the two variables and the semi colon at the end.

qtdisplay.php would contain this code...

Code: Select all

<head>
<title>
<? print($title); ?>
</title>
</head>
<body>
<br>
<center>
<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="320"HEIGHT="256" CODEBASE ="http://www.apple.com/qtactivex/qtplugin.cab">
<PARAM name="SRC" VALUE="http://dakev.com/qt/<? print($movie); ?>">
<PARAM name="AUTOPLAY" VALUE="false">
<PARAM name="CONTROLLER" VALUE="true">
<EMBED SRC="http://thekeverreport.com/qt/<? print($movie); ?>" WIDTH="320" HEIGHT="256" AUTOPLAY="false" CONTROLLER="true" PLUGINSPAGE="http://www.apple.com/quicktime/download/">
</EMBED>
</OBJECT>
</center>

Any help would be greatly appreciated.

Posted: Mon Jun 19, 2006 6:00 pm
by RobertGonzalez
Cool, another convert :twisted: .

First things first, welcome to PHP and the PHP Developers Network Forums. Here are a few recommendations...

1) Use complete tags (<?php)instead of short tags (<?) for opening your PHP code. There is a possibility that someday short tags may not be supported and your code would have to be rewritten. Worse yet, your host may not support short tags in their PHP installation, which would result in you having to rewrite your code.

2) You can use echo parallel to print. So your title, for example, could be written as...

Code: Select all

<title><?php echo $title; ?></title>
3) As for your echoing of the link structure, you could do it just like you have. The ampersand between the variable is just your querystring separator. The semicolon is PHP's way of ending a line of code.

Hope that helps. And, again, welcome to the forums.

Posted: Mon Jun 19, 2006 6:06 pm
by Christopher
Not sure what "x" is but it might be an object:

Code: Select all

http://www.dakev.com/qtdisplay.php?movie=<?php echo $x->mov; ?>&title=<?php echo $x->title; ?>;
Or an array:

Code: Select all

http://www.dakev.com/qtdisplay.php?movie=<?php echo $x['mov']; ?>&title=<?php echo $x['title']; ?>;

Thanks.

Posted: Tue Jun 20, 2006 12:22 am
by dakev
x.mov would be the name of my quicktime movie I'm passing as a variable.

Thanks for the reply. I'll write this script out, publish it, and let you know how it works.

having problems

Posted: Tue Jun 20, 2006 11:32 am
by dakev
Okay this is a stupid question.

Code: Select all

<a href="qtdisplay.php?movie=<?php echo=$911.mov; ?>&title=<?php echo=$Title; ?>;">to watch movie click here</a>
I’m placing this code in my wordpress post template so all I need to do is change the variables. But it’s not working and I think I know why.

html is thinking the “>” is the end of its tag when in all actuality it’s the end of the PHP tag. How can I get around this? I think there is an escape character but I don’t remember what it is. Do you think an escape character will fix the problem?

I may need to do this all with javascripting, which is how I was doing it on the windows box. I just wanted to avoid the extra step.

Posted: Tue Jun 20, 2006 11:36 am
by feyd
it's not working for several reasons. First, the = after each echo shouldn't be there. Second, '.mov' will be processed wrong. Read up on how strings work here: http://php.net/language.types.string

Re: having problems

Posted: Tue Jun 20, 2006 11:39 am
by RobertGonzalez
When run through the parser, the PHP gets processed then applied to the HTML, so it wouldn't get confused. One thing that will cause you some issue is the .mov part added to your $911 var, which is also incorrect. You cannot start a vaiable name with a number (only alpha chars and underscores). You may need to echo the movie name variable and add the .mov part after the closing PHP tag.

Try this in your code...

Code: Select all

<?php
$moviename = 'nameofthemovie';
$title = 'Title to display';
?>

<a href="qtdisplay.php?movie=<?php echo $moviename; ?>.mov&title=<?php echo $title; ?>">to watch movie click here</a>

Thanks a whole lot.

Posted: Tue Jun 20, 2006 2:28 pm
by dakev
I appreciate all the feedback. It looks like there is a fairly decent learning curve switching from asp. I think I'm up to it though... especially with this active forum.

It looks like WordPress is getting confused with the php.

Here is the code within the post.

Code: Select all

this is before the code.

<?php 
$moviename = '911.mov'; 
$title = 'Title';
?>

<a href="qtdisplay.php?movie=<?php echo $moviename; ?>.mov&title=<?php echo $title; ?>">to watch movie click here</a>

This is after the code.
Now check out how the page displays.

http://www.thekeverreport.com/tkr/?p=44

I'm thinking I may need to define a JavaScript popup function to accept the variables and call the php from there... which is how I did it with ASP... but I was trying to avoid that step in the interest of efficiency.

Re: Thanks a whole lot.

Posted: Tue Jun 20, 2006 3:05 pm
by RobertGonzalez
dakev wrote:It looks like WordPress is getting confused with the php.
Actually, when you add code to a post in WordPress it gets parsed out, meaning the code will not execute in the display. If you want the link to appear normal in the posting, you should just reference it within the post itself, ie...

<a href="qtdisplay.php?movie=911.mov&title=Title">to watch movie click here</a>

WordPress will display it as a link.

Okay...

Posted: Tue Jun 20, 2006 3:39 pm
by dakev
So when I do that, it calls the php page but it's not passing the variables.

Try it.

http://www.thekeverreport.com/tkr/qtdis ... itle=Title

It will pull up a blank page.

Look at the source... the variables are not coming through.

Here's the source for qtdisplay.php

Code: Select all

<head>
<title>
<?php print($title); ?>
</title>
</head>
<body>
<br>
<center>
<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="320"HEIGHT="256" CODEBASE 

="http://www.apple.com/qtactivex/qtplugin.cab">
<PARAM name="SRC" VALUE="wp-content/qt/<?php print($movie); ?>">
<PARAM name="AUTOPLAY" VALUE="false">
<PARAM name="CONTROLLER" VALUE="true">
<EMBED SRC="wp-content/qt/<?php print($movie); ?>" WIDTH="320" HEIGHT="256" AUTOPLAY="false" CONTROLLER="true" 

PLUGINSPAGE="http://www.apple.com/quicktime/download/">
</EMBED>
</OBJECT>
</center>

Re: Okay...

Posted: Tue Jun 20, 2006 6:06 pm
by RobertGonzalez
OK, I get what you are trying to do now. You want PHP's version of Request.QueryString. Do this in your qtdisplay.php page...

Code: Select all

<?php
$title = $_GET['title'];
$movie = $_GET['movie'];
?>
<head>
<title>
<?php echo $title; ?>
</title>
</head>
<body>
<br>
<center>
<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="320"HEIGHT="256" CODEBASE 

="http://www.apple.com/qtactivex/qtplugin.cab">
<PARAM name="SRC" VALUE="wp-content/qt/<?php echo $movie; ?>">
<PARAM name="AUTOPLAY" VALUE="false">
<PARAM name="CONTROLLER" VALUE="true">
<EMBED SRC="wp-content/qt/<?php echo $movie; ?>" WIDTH="320" HEIGHT="256" AUTOPLAY="false" CONTROLLER="true" 

PLUGINSPAGE="http://www.apple.com/quicktime/download/">
</EMBED>
</OBJECT>
</center>
If you had register_globals set to on, your first code would have worked. But it is better to leave them off, so doing it this way is a lot safer. I would also recommend some input validation, but start with this and see if it works.

Grazi

Posted: Wed Jun 21, 2006 12:11 am
by dakev
That did it. You’re a genius.

Now I just have to figure out how to turn it into a pop-up… but that should be easy.

Thanks very much for your help.

Posted: Wed Jun 21, 2006 12:19 am
by RobertGonzalez
Genius... I like the sound of that...

/ Blushes in humility :oops: