javascript in php

This is a discussion on "javascript in php" within the PHP Forum section. This forum, and the thread "javascript in php are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 13th, 2008, 20:30
Junior Member
Join Date: Feb 2008
Location: U.S.A
Age: 26
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
javascript in php

hey what i am trying to do is basically if the user didnt get the right pasword, they are sent away to some other site, but for some reason, the javascript does not work inside the php thing... i tried the little javascript segment outside and it worked fine. am i missing something here? thanks

<?php
if ($_POST["Psword"] != "MyPassword")
{
echo "<script type="text/javascript">window.location="http://www.google.com"</script>"
}

?>
Reply With Quote

  #2 (permalink)  
Old Feb 13th, 2008, 21:15
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,649
Thanks: 0
Thanked 8 Times in 8 Posts
Send a message via MSN to Marc Send a message via Skype™ to Marc
Re: javascript in php

Why dont you use:

PHP: Select all

if ($_POST["Psword"] != "MyPassword")
{
header("Location: http://www.google.co.uk");


OR if you want your JavaScript to work.. you have to escape the ".

PHP: Select all

<?php
if ($_POST["Psword"] != "MyPassword")
{
     echo 
"<script type=\"text/javascript\">window.location=\"http://www.google.com\"</script>";
}
 
?>
Good luck!
Reply With Quote
  #3 (permalink)  
Old Feb 13th, 2008, 21:30
Jack Franklin's Avatar
Resources Administrator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,268
Blog Entries: 7
Thanks: 10
Thanked 4 Times in 4 Posts
Re: javascript in php

Marc's first version is recommended - javascript can be turned off, PHP cannot.
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
php and javascript yvettesio JavaScript Forum 8 Mar 14th, 2007 23:18
JavaScript cbrams9 JavaScript Forum 1 Sep 20th, 2006 17:35
using xml in javascript shailu JavaScript Forum 0 Jul 25th, 2006 07:36
Can someone help me with this javascript Galaxyblue JavaScript Forum 2 Mar 11th, 2004 12:18
what does \\ mean in javascript jenjen1018 JavaScript Forum 5 Jan 6th, 2004 17:05


All times are GMT. The time now is 11:52.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43