ASP to PHP

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
dakev
Forum Newbie
Posts: 6
Joined: Mon Jun 19, 2006 5:45 pm

ASP to PHP

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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']; ?>;
(#10850)
dakev
Forum Newbie
Posts: 6
Joined: Mon Jun 19, 2006 5:45 pm

Thanks.

Post 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.
dakev
Forum Newbie
Posts: 6
Joined: Mon Jun 19, 2006 5:45 pm

having problems

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: having problems

Post 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>
dakev
Forum Newbie
Posts: 6
Joined: Mon Jun 19, 2006 5:45 pm

Thanks a whole lot.

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Thanks a whole lot.

Post 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.
dakev
Forum Newbie
Posts: 6
Joined: Mon Jun 19, 2006 5:45 pm

Okay...

Post 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>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Okay...

Post 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.
dakev
Forum Newbie
Posts: 6
Joined: Mon Jun 19, 2006 5:45 pm

Grazi

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Genius... I like the sound of that...

/ Blushes in humility :oops:
Post Reply