/    Sign up×
Community /Pin to ProfileBookmark

PHP with Java Script

Anyone know how to include java script code in PHP? I have try it but the JavaScript code (in the head section) did’t function at all. Below is my code for testing on it,

######## START ########
<?php
echo”<html>”;
echo”<head>”;
echo”<!–paste in the head section of the page–>”;

echo”<SCRIPT language=”JavaScript”>”;
echo”<!– [url]http://www.spacegun.co.uk[/url] –>”;
echo”var message = “function disabled”; “;
echo” function rtclickcheck(keyp){ if (navigator.appName == “Netscape” && keyp.which ==”3″){ alert(message); return false; } “;
echo” if (navigator.appVersion.indexOf(“MSIE”) !=”-1″ && event.button ==”2″) { alert(message); return false; } } “;
echo” document.onmousedown = “rtclickcheck”;”;
echo”</SCRIPT>”;
echo”</head>”;
echo”<body>”;
echo”Right click me!!<br>”;
echo”<center><img src=”http://tkyoko/webportal/modules/5S_Program/images/Logo.jpg” width=”550″ height=”405″></center><br><br>”;
echo”</body>”;
?>

####### END ###########

Thanks.

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@JonaApr 14.2004 — [font=arial]Can you post just the JavaScript output?[/font]
Copy linkTweet thisAlerts:
@chestertbApr 14.2004 — Assuming your javascript is right, the following will work...

<?php

print "<html>

<head>

<!--paste in the head section of the page-->

<SCRIPT language='JavaScript'>

<!-- http://www.spacegun.co.uk -->

var message = 'function disabled';

function rtclickcheck(keyp){ if (navigator.appName == 'Netscape' && keyp.which =='3'){ alert(message); return false; }

if (navigator.appVersion.indexOf('MSIE') !='-1' && event.button =='2') { alert(message); return false; } }

document.onmousedown = 'rtclickcheck';

</SCRIPT>

</head>

<body>

Right click me!!<br>

<center><img src='http://tkyoko/webportal/modules/5S_Program/images/Logo.jpg' width='550' height='405'></center><br><br>

</body>

";

?>

Note... I ditched all the "echo" statements, and just used a single "print" statement. Makes it a little easier to read

CTB
Copy linkTweet thisAlerts:
@DaiWelshApr 14.2004 — Or just put it in your template as regular HTML, you do not seem to be using any PHP functionality in creating the javascript so you are just creating needless work for the processor by doing it that way.
Copy linkTweet thisAlerts:
@yllaiauthorApr 15.2004 — my page is coded with php..I just want to include some java script function..as what I attached is disable right click function.

Any how, I have done it...

<?php

//p code here

echo"<head>";

?>

Java script here

<?php

echo"</head>";

//php code here
>

don't put the java script in php mode @ within '<?php' and ' ?>'


Thanks for all reply.
Copy linkTweet thisAlerts:
@ConorApr 15.2004 — whats the point in disabling right click?
Copy linkTweet thisAlerts:
@chestertbApr 15.2004 — Observation...

I leave any page that has right click disabled, and don't go back.

Right click isn't just used to access source code or copy pictures. I use on almost every link to open that link in a new browser tab (Crazy Browser or Mozilla/Netscape).

If you have source code you want protected, put it server-side. As for your photos, it doesn't much matter what you do... if someone wants an image from your site that badly, they're going to get it anyway (like pressing [alt-print screen] on a pc).

Of course, disabling right click is a favourite trick of spammers everywhere. It allows them to assemble pages out of sequences of characters that combine printable characters with non printable characters, and then hide the source from view, making it harder for system admin people to add those words or sequences to spam filters.

I'd hate to think you were a spammer, and accessing the goodwill in a forum like this just so you can bombard us with trash later.

Let them right click.

CTB
Copy linkTweet thisAlerts:
@yllaiauthorApr 15.2004 — Chestertb, I know....I dint restrict user right click ...that is my first way to restrict user from copying images..but now a day I know that is no point...
Copy linkTweet thisAlerts:
@chestertbApr 15.2004 — Nope. No point. Welcome to the 21st Century.

Suggestion, though. If you want to protect your images, you could put a watermark through them.

Good luck with it.

CTB
Copy linkTweet thisAlerts:
@yllaiauthorApr 15.2004 — No! Cant be! If you do it with watermark...user still can save the watermarked image and then use image editor appilication to edit it..control the brightness and contra.....they still can get the image at the end..just need some time...
×

Success!

Help @yllai spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...