/    Sign up×
Community /Pin to ProfileBookmark

PHP embedding in HTML

Can PHP script be embedded in an HTML file?

I’m trying to get a individuals’ IP Address when they visit a site, and I need the variable passed to JavaScript. ?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@The_CheatMar 29.2004 — this will get the users ip address
[code=php]<?php
$ip = $_SERVER['REMOTE_ADDR'];

echo "$ip";
?>[/code]
Copy linkTweet thisAlerts:
@Tony_shuauthorMar 29.2004 — can i embed that in the head or body of an html page?

When I try..it doesn't print or "echo" anything

If I can't print/echo the variable, is there a way to perhaps divide each digit into an array?

For Example...if my ip is 123.456.789.012

I know how to do it in PERL:
[CODE]my $ip = $ENV{REMOTE_ADDR};
$ip =~ s/.//ig;
my @ipdigits = split(//,$ip);[/CODE]
Copy linkTweet thisAlerts:
@ConorMar 29.2004 — you cant put it in a html document unless you have the <?php ?> tags around it is saved as a .php. You can not put php in a .html page.
Copy linkTweet thisAlerts:
@pyroMar 29.2004 — [i]Originally posted by RefreshF5 [/i]

[B]You can not put php in a .html page. [/B][/QUOTE]
Unless you modify the server to parse .html files as PHP, either through the httpd.conf file or a .htaccess file. But yes, generally speaking, files will have to have a .php extention.
×

Success!

Help @Tony_shu 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 4.30,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...