i know i can use $_SERVER['REMOTE_ADDR'] to retrieve the client IP, but is there a way to retrieve the server IP using the script? the thing is, i need to compare the server and the client IPs to see if theyre the same for a script im makingthey should never be the same
$_SERVER["SERVER_ADDR"]well y dont you just run<?php
phpinfo();
?>
And it shows all PHP variables... then you just add the variable to your site!
and yea, im sure it is $_SERVER['SERVER_ADDR']Originally posted by scoutt
they should never be the same
$_SERVER["SERVER_ADDR"]
Based on previous conversations with him..I'd say he means to check if the ip is the same as the server...because hes hosting the script locally on the same comp he'll be running it from.To make sure it's just him running it from his own comp..which is understandable, but then you would want to check the form POSTed values. have a hidden value you expect or the referrer is from you only. but an IP is not a sure way.:doh: i should have guessed that
thanks for the info AHHQ_MAn
which is understandable, but then you would want to check the form POSTed values. have a hidden value you expect or the referrer is from you only. but an IP is not a sure way.
im using GET not POST if that has anything to do with what you just said
heres the script in its entirety:
<html>
<?
$mysql_server = "localhost";
$mysql_user = "morrowasted";
$mysql_password = "******";
$server = "localhost";
mysql_connect ($mysql_server, $mysql_user, $mysql_password) or die(mysql_error());
mysql_select_db ("www");
$story = strip_tags(addslashes($_GET["story"]));
$author = strip_tags(addslashes($_GET["author"]));
$date = strip_tags(addslashes($_GET["date"]));
if ($_SERVER['REMOTE_ADDR']==$_SERVER['SERVER_ADDR']){
if (trim($_GET["story"]) !=' ' && trim($_GET["story"]) !=' ') {
if (trim($_GET["story"]) !='') {
mysql_query("INSERT INTO `ltc` (`author`, `story`, `dar`) VALUES ('$author', '$story', '$date')") or die(mysql_error());
}
}
}
mysql_close();
?>
<?
$mysql_server = "localhost";
$mysql_user = "morrowasted";
$mysql_password = "virginia";
$server = "localhost";
$query = "SELECT * FROM ltc ORDER BY id DESC";
mysql_connect ($mysql_server, $mysql_user, $mysql_password) or die(mysql_error());
mysql_select_db ("www");
$result2=mysql_query($query);
while($row = mysql_fetch_array($result2))
{
echo "<div style='margin-left:2px;background-color: darkblue;border:2px solid black; -moz-border-radius:8px;'>";
echo "<div style='margin-left:2px;background-color:#ccffcc;font-family:georgia;font-size:11px;border:1px solid darkgreen;-moz-border-radius:5px;'>". ''.$row["story"]."</div>";
echo "<div style='margin-left:2px;background-color:#ccffcc;font-family:georgia;font-size:11px;border:1px solid darkgreen;-moz-border-radius:5px;'>"."<b>Author:</b>". ''.$row["author"]."</div>";
echo "<div style='margin-left:2px;background-color:#ccffcc;font-family:georgia;font-size:11px;border:1px solid darkgreen;-moz-border-radius:5px;'>"."<b>Date Written:</b>". ''.$row["dar"]."</div>";
echo "</div>" . "<br />";
}
?></div>
<form action="ltc.php" method="get">
<textarea rows="20" name="story" style="width:100%;font-family:arial;font-size:10;border:2px solid black;background-color:lightblue;overflow:auto;-moz-border-radius:5px;"></textarea>
Author:<input type="text" name="author" style="font-family:arial;font-size:10;border:2px solid black;background-color:lightblue;width:10%;align:center;-moz-border-radius:5px;"><br>
Date: <input type="text" name="date" style="margin-left:1px;font-family:arial;font-size:10;border:2px solid black;background-color:lightblue;width:10%;align:center;-moz-border-radius:5px;"><br>
<input type="submit" value="post" style="margin-left:1px;font-family:arial;font-size:10;border:2px solid black;background-color:lightgreen;width:10%;align:center;-moz-border-radius:5px;">
</form>
<? $log="/hits3.txt"; //hits.txt will store the number of hits.
$open=fopen($log,'r+');
$counter=fread($open,filesize($log)); //now we will close the log file...
fclose($open); $counter++; $write=fopen($log,'w');
fputs($write,$counter); fclose($write);
echo $counter; echo " hits"; ?>
just point out what you mean why GET? you are limited to how many characters you can send in the url. and why are you connecting to the db twice?
also I changed a few thing. I would change it to post and if this doesn't work we can try the referer a different way.
<html>
<?php
$mysql_server = "localhost";
$mysql_user = "morrowasted";
$mysql_password = "******";
$server = "localhost";
mysql_connect ($mysql_server, $mysql_user, $mysql_password) or die(mysql_error());
mysql_select_db ("www");
if ($_GET['author']){
$story = strip_tags(addslashes($_GET["story"]));
$author = strip_tags(addslashes($_GET["author"]));
$date = strip_tags(addslashes($_GET["date"]));
// theses will NEVER be the same
//if ($_SERVER['REMOTE_ADDR']==$_SERVER['SERVER_ADDR']){
// I think this will work, can't remember
if ($_SERVER['HTTP_REFERER']==$_SERVER['SCRIPT_NAME']){
if (trim($_GET["story"]) !=' ' && trim($_GET["story"]) !=' ') {
if (trim($_GET["story"]) !='') {
mysql_query("INSERT INTO `ltc` (`author`, `story`, `dar`) VALUES ('$author', '$story', '$date')") or die(mysql_error());
}
}
}
} else {
//
// where is your head and body tags?
//
$query = "SELECT * FROM ltc ORDER BY id DESC";
$result2=mysql_query($query);
while($row = mysql_fetch_array($result2))
{
echo "<div style='margin-left:2px;background-color: darkblue;border:2px solid black; -moz-border-radius:8px;'>";
echo "<div style='margin-left:2px;background-color:#ccffcc;font-family:georgia;font-size:11px;border:1px solid darkgreen;-moz-border-radius:5px;'>". ''.$row["story"]."</div>";
echo "<div style='margin-left:2px;background-color:#ccffcc;font-family:georgia;font-size:11px;border:1px solid darkgreen;-moz-border-radius:5px;'>"."<b>Author:</b>". ''.$row["author"]."</div>";
echo "<div style='margin-left:2px;background-color:#ccffcc;font-family:georgia;font-size:11px;border:1px solid darkgreen;-moz-border-radius:5px;'>"."<b>Date Written:</b>". ''.$row["dar"]."</div>";
echo "</div>" . "<br />";
}
?>
<form action="ltc.php" method="get">
<textarea rows="20" name="story" style="width:100%;font-family:arial;font-size:10;border:2px solid black;background-color:lightblue;overflow:auto;-moz-border-radius:5px;"></textarea>
Author:<input type="text" name="author" style="font-family:arial;font-size:10;border:2px solid black;background-color:lightblue;width:10%;align:center;-moz-border-radius:5px;"><br>
Date: <input type="text" name="date" style="margin-left:1px;font-family:arial;font-size:10;border:2px solid black;background-color:lightblue;width:10%;align:center;-moz-border-radius:5px;"><br>
<input type="submit" value="post" style="margin-left:1px;font-family:arial;font-size:10;border:2px solid black;background-color:lightgreen;width:10%;align:center;-moz-border-radius:5px;">
</form>
<?
// close html??
$log="/hits3.txt"; //hits.txt will store the number of hits.
$open=fopen($log,'r+');
$counter=fread($open,filesize($log)); //now we will close the log file...
fclose($open); $counter++; $write=fopen($log,'w');
fputs($write,$counter); fclose($write);
echo $counter; echo " hits"; ?>ummm
scoutt.. why wont they be the same?
the script still works, i can post :/
ill try what you posted though.
<!-- m --><a class="postlink" href="http://24.238.145.68/public/ltc2.php">http://24.238.145.68/public/ltc2.php</a><!-- m -->
Parse error: parse error in c:\phpdev\www\public\ltc2.php on line 55
Line 55: echo $counter; echo " hits";
anyway, i use the GET method cuz its the only one i know how to use.. would it be a lot different if i used POST? would it have to be in two seperate files, because i like having it all in one fileyou can have it all in the same file. POST just doesn't send it in the url. that error is not mine, I didn't touch that part. but I did forgoet to add a } at the end of the form.
$_SERVER['REMOTE_ADDR'] = the IP of the user
$_SERVER['SERVER_ADDR'] = the IP of the server
if they are then you have issues. IP's are uniquescoutt, lemme clear this up.
the script is running on my computer, at 24.238.145.68. when i go to the script, ON MY COMPUTER, the client IP is me, 24.238.145.68. so they are the same
if i just change the form method to POST would it work the same :/?if it is just you then why have it?
and yes, if you use POST it will work the same.Originally posted by scoutt
if it is just you then why have it?
and yes, if you use POST it will work the same. ummm becuase i dont want other people to post :/Ok i changed it to POST, works fine.
thanks for all the help guys Originally posted by Gregory
ummm becuase i dont want other people to post :/
then don't give out the page
but I see what you mean. then just make it password protected.
$_SERVER["SERVER_ADDR"]well y dont you just run<?php
phpinfo();
?>
And it shows all PHP variables... then you just add the variable to your site!
and yea, im sure it is $_SERVER['SERVER_ADDR']Originally posted by scoutt
they should never be the same
$_SERVER["SERVER_ADDR"]
Based on previous conversations with him..I'd say he means to check if the ip is the same as the server...because hes hosting the script locally on the same comp he'll be running it from.To make sure it's just him running it from his own comp..which is understandable, but then you would want to check the form POSTed values. have a hidden value you expect or the referrer is from you only. but an IP is not a sure way.:doh: i should have guessed that
thanks for the info AHHQ_MAn
which is understandable, but then you would want to check the form POSTed values. have a hidden value you expect or the referrer is from you only. but an IP is not a sure way.
im using GET not POST if that has anything to do with what you just said
heres the script in its entirety:
<html>
<?
$mysql_server = "localhost";
$mysql_user = "morrowasted";
$mysql_password = "******";
$server = "localhost";
mysql_connect ($mysql_server, $mysql_user, $mysql_password) or die(mysql_error());
mysql_select_db ("www");
$story = strip_tags(addslashes($_GET["story"]));
$author = strip_tags(addslashes($_GET["author"]));
$date = strip_tags(addslashes($_GET["date"]));
if ($_SERVER['REMOTE_ADDR']==$_SERVER['SERVER_ADDR']){
if (trim($_GET["story"]) !=' ' && trim($_GET["story"]) !=' ') {
if (trim($_GET["story"]) !='') {
mysql_query("INSERT INTO `ltc` (`author`, `story`, `dar`) VALUES ('$author', '$story', '$date')") or die(mysql_error());
}
}
}
mysql_close();
?>
<?
$mysql_server = "localhost";
$mysql_user = "morrowasted";
$mysql_password = "virginia";
$server = "localhost";
$query = "SELECT * FROM ltc ORDER BY id DESC";
mysql_connect ($mysql_server, $mysql_user, $mysql_password) or die(mysql_error());
mysql_select_db ("www");
$result2=mysql_query($query);
while($row = mysql_fetch_array($result2))
{
echo "<div style='margin-left:2px;background-color: darkblue;border:2px solid black; -moz-border-radius:8px;'>";
echo "<div style='margin-left:2px;background-color:#ccffcc;font-family:georgia;font-size:11px;border:1px solid darkgreen;-moz-border-radius:5px;'>". ''.$row["story"]."</div>";
echo "<div style='margin-left:2px;background-color:#ccffcc;font-family:georgia;font-size:11px;border:1px solid darkgreen;-moz-border-radius:5px;'>"."<b>Author:</b>". ''.$row["author"]."</div>";
echo "<div style='margin-left:2px;background-color:#ccffcc;font-family:georgia;font-size:11px;border:1px solid darkgreen;-moz-border-radius:5px;'>"."<b>Date Written:</b>". ''.$row["dar"]."</div>";
echo "</div>" . "<br />";
}
?></div>
<form action="ltc.php" method="get">
<textarea rows="20" name="story" style="width:100%;font-family:arial;font-size:10;border:2px solid black;background-color:lightblue;overflow:auto;-moz-border-radius:5px;"></textarea>
Author:<input type="text" name="author" style="font-family:arial;font-size:10;border:2px solid black;background-color:lightblue;width:10%;align:center;-moz-border-radius:5px;"><br>
Date: <input type="text" name="date" style="margin-left:1px;font-family:arial;font-size:10;border:2px solid black;background-color:lightblue;width:10%;align:center;-moz-border-radius:5px;"><br>
<input type="submit" value="post" style="margin-left:1px;font-family:arial;font-size:10;border:2px solid black;background-color:lightgreen;width:10%;align:center;-moz-border-radius:5px;">
</form>
<? $log="/hits3.txt"; //hits.txt will store the number of hits.
$open=fopen($log,'r+');
$counter=fread($open,filesize($log)); //now we will close the log file...
fclose($open); $counter++; $write=fopen($log,'w');
fputs($write,$counter); fclose($write);
echo $counter; echo " hits"; ?>
just point out what you mean why GET? you are limited to how many characters you can send in the url. and why are you connecting to the db twice?
also I changed a few thing. I would change it to post and if this doesn't work we can try the referer a different way.
<html>
<?php
$mysql_server = "localhost";
$mysql_user = "morrowasted";
$mysql_password = "******";
$server = "localhost";
mysql_connect ($mysql_server, $mysql_user, $mysql_password) or die(mysql_error());
mysql_select_db ("www");
if ($_GET['author']){
$story = strip_tags(addslashes($_GET["story"]));
$author = strip_tags(addslashes($_GET["author"]));
$date = strip_tags(addslashes($_GET["date"]));
// theses will NEVER be the same
//if ($_SERVER['REMOTE_ADDR']==$_SERVER['SERVER_ADDR']){
// I think this will work, can't remember
if ($_SERVER['HTTP_REFERER']==$_SERVER['SCRIPT_NAME']){
if (trim($_GET["story"]) !=' ' && trim($_GET["story"]) !=' ') {
if (trim($_GET["story"]) !='') {
mysql_query("INSERT INTO `ltc` (`author`, `story`, `dar`) VALUES ('$author', '$story', '$date')") or die(mysql_error());
}
}
}
} else {
//
// where is your head and body tags?
//
$query = "SELECT * FROM ltc ORDER BY id DESC";
$result2=mysql_query($query);
while($row = mysql_fetch_array($result2))
{
echo "<div style='margin-left:2px;background-color: darkblue;border:2px solid black; -moz-border-radius:8px;'>";
echo "<div style='margin-left:2px;background-color:#ccffcc;font-family:georgia;font-size:11px;border:1px solid darkgreen;-moz-border-radius:5px;'>". ''.$row["story"]."</div>";
echo "<div style='margin-left:2px;background-color:#ccffcc;font-family:georgia;font-size:11px;border:1px solid darkgreen;-moz-border-radius:5px;'>"."<b>Author:</b>". ''.$row["author"]."</div>";
echo "<div style='margin-left:2px;background-color:#ccffcc;font-family:georgia;font-size:11px;border:1px solid darkgreen;-moz-border-radius:5px;'>"."<b>Date Written:</b>". ''.$row["dar"]."</div>";
echo "</div>" . "<br />";
}
?>
<form action="ltc.php" method="get">
<textarea rows="20" name="story" style="width:100%;font-family:arial;font-size:10;border:2px solid black;background-color:lightblue;overflow:auto;-moz-border-radius:5px;"></textarea>
Author:<input type="text" name="author" style="font-family:arial;font-size:10;border:2px solid black;background-color:lightblue;width:10%;align:center;-moz-border-radius:5px;"><br>
Date: <input type="text" name="date" style="margin-left:1px;font-family:arial;font-size:10;border:2px solid black;background-color:lightblue;width:10%;align:center;-moz-border-radius:5px;"><br>
<input type="submit" value="post" style="margin-left:1px;font-family:arial;font-size:10;border:2px solid black;background-color:lightgreen;width:10%;align:center;-moz-border-radius:5px;">
</form>
<?
// close html??
$log="/hits3.txt"; //hits.txt will store the number of hits.
$open=fopen($log,'r+');
$counter=fread($open,filesize($log)); //now we will close the log file...
fclose($open); $counter++; $write=fopen($log,'w');
fputs($write,$counter); fclose($write);
echo $counter; echo " hits"; ?>ummm
scoutt.. why wont they be the same?
the script still works, i can post :/
ill try what you posted though.
<!-- m --><a class="postlink" href="http://24.238.145.68/public/ltc2.php">http://24.238.145.68/public/ltc2.php</a><!-- m -->
Parse error: parse error in c:\phpdev\www\public\ltc2.php on line 55
Line 55: echo $counter; echo " hits";
anyway, i use the GET method cuz its the only one i know how to use.. would it be a lot different if i used POST? would it have to be in two seperate files, because i like having it all in one fileyou can have it all in the same file. POST just doesn't send it in the url. that error is not mine, I didn't touch that part. but I did forgoet to add a } at the end of the form.
$_SERVER['REMOTE_ADDR'] = the IP of the user
$_SERVER['SERVER_ADDR'] = the IP of the server
if they are then you have issues. IP's are uniquescoutt, lemme clear this up.
the script is running on my computer, at 24.238.145.68. when i go to the script, ON MY COMPUTER, the client IP is me, 24.238.145.68. so they are the same
if i just change the form method to POST would it work the same :/?if it is just you then why have it?
and yes, if you use POST it will work the same.Originally posted by scoutt
if it is just you then why have it?
and yes, if you use POST it will work the same. ummm becuase i dont want other people to post :/Ok i changed it to POST, works fine.
thanks for all the help guys Originally posted by Gregory
ummm becuase i dont want other people to post :/
then don't give out the page
but I see what you mean. then just make it password protected.