School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store | FORUMS

Class / Forums / php101 Refresh the current page Week #7 Basic To-Do Assignment, post here
 

 (#12 2003-08-07 16:22:44) Post Reply

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

Week #7 Basic To-Do ASSIGNMENT: Write a script to print the IP address if a surfer comes from a bookmark or type-in and show their browser type, and if the person comes from YOUR domain then print a clickable url.

Post this assignment here so that we can offer comment/critique for you, but also post a URL to the working copy of the script and post the complete source code here.

scriptname.php <-- script name

Good luck to you!

 

 (#80 2003-08-21 12:24:34) Post Reply

Sk8rRIMuk
Need To Set


Enrolled: Aug 2003
Posts: 39
AP: 1

A little bit easier than the previous weeks but still a very handy script which I will be sure to put to use in some way on my new website when I have finished it.

Heres the URL to my working script:
http://www.katikai.com/ee/assi...0Assignment.php

As usual all my past assignments are at:
http://www.katikai.com/ee/assignment

Heres the source for my page:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Week #2 ADVANCED To-Do Assignment</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<center><?php
//Check to see if HTTP_REFERER is blank if so print IP and Browser Typw
if(!$HTTP_REFERER){print("Yourweredirectedhereviaabookmarkortype-inyourip
addressis$REMOTE_ADDRandyourbrowsertypeis$HTTP_USER_AGENT"
);}
/* If there is a HTTP_REFERER (ie refered via a page) print the referer as a clickable
URL */
else{print("You were directed to this page from <a href="$HTTP_REFERER"
target="
_blank">$HTTP_REFERER</a>");}
?>
</center>
</body>
</html>



I really like this assignment I can't wait to get started on the Advamced version but it shall ahve to wait a little longer seeing as I am gonna be celebrating my GCSE results :)

I got 8 c's (including ICT & ART) a D (in english speaking and listening) and a B (in maths).

Just incase you wnated to know.

 

 (#181 2003-09-10 14:03:32) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

here, easy :)


<?
$mydomain
= "http://quicksaver.coolfreepage.com/";

if(
eregi("$mydomain", $HTTP_REFERER)) {
print(
"<a href=\"$mydomain\">$mydomain</a>"); } else {
print(
"Your IP: $REMOTE_ADDR<br>Your browser: $HTTP_USER_AGENT"); }
?>



working url and i made this one to test out the script

 

 (#182 2003-09-10 14:21:20) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

and i noticed now that i dont have to hardcode my domain, i can do the same with the envinonmental variables



<?
$mydomain
= "http://$SERVER_NAME";

if(
eregi("$mydomain", $HTTP_REFERER)) {
print(
"<a href=\"$mydomain\">$mydomain</a>"); } else {
print(
"Your IP: $REMOTE_ADDR<br>Your browser: $HTTP_USER_AGENT"); }
?>




working url and another redirect

 

 (#183 2003-09-10 14:24:16) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

and of course all those could be resumed with the !$HTTP_REFERER way that sk8r used :)

 

 (#236 2003-09-18 02:31:54) Post Reply

Shrek
Need To Set


Enrolled: Aug 2003
Posts: 33
AP: 1

Here is my Assignment
HTML link to PHP http://members.lycos.co.uk/jef...wan/class07.htm
The PHP File http://members.lycos.co.uk/jef...wan/class07.php




<?
if(!$_SERVER['HTTP_REFERER'])
{
echo (
"<b>Welcome From ".$_SERVER['REMOTE_ADDR']."</b></br>");
echo (
"You are now using ".$_SERVER['HTTP_USER_AGENT']." to browse this page </br>");
}
else
{
echo (
"Come to see something special. <br>");
echo (
"<a href='http://class.scriptschool.com/forums/php101/view/12/'>Class 7 Basic Assignment</a>");
}
?>




 

 (#443 2003-12-31 02:06:15) Post Reply

PureGrain
Need To Set


Enrolled: Nov 2003
Posts: 14
AP: 1

Here is week 7:



<html>
<head>
<title>Lesson 7</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><p align="center">Week #7 Basic To-Do ASSIGNMENT: Write a script to print the IP address if a surfer comes from a bookmark or type-in and show their browser type, and if the person comes from YOUR domain then print a clickable url. </p>
<p align="center">Code begins below this line:</p>
<hr>
<?php
//Check for blank $HTTP_REFERER
$domain = "http://$SERVER_NAME";
if(!
$HTTP_REFERER)
{
print(
"You were directed to this site from this IP: $REMOTE_ADDR" . "<br>" . "Your browser type is: $HTTP_USER_AGENT");
}
else
{
print(
"$domain");
}
?>
</body>
</html>



Working URL: http://members.lycos.co.uk/xko...on7/lesson7.php
Redirect:http://members.lycos.co.uk/xkoremaster/lesson7/redirect.php

Thanks for the redirect idea Quik :D

 

 (#444 2003-12-31 02:07:10) Post Reply

PureGrain
Need To Set


Enrolled: Nov 2003
Posts: 14
AP: 1

oops.. did not space between the last url

redirect: http://members.lycos.co.uk/xko...n7/redirect.php

Sorry for double post.

 

 (#449 2004-01-03 16:33:30) Post Reply

Ahkorahil
Need To Set


Enrolled: Oct 2003
Posts: 20
AP: 1


// This code has an error and unfortunately I don't find the mistake so could U help me very little?
// Browser tells that error is on the 11th row
[if(strlen($ip) < 6)..... ]


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> 7. home assignment </TITLE>
</HEAD>
<BODY>
<!-- (basic) TO-DO ASSIGNMENT: Write a script to print the IP address if a surfer comes from a bookmark or type-in and show their browser type, and if the person comes from YOUR domain then print a clickable url. -->
<?php
$minudomeen= "http://www.zone.ee/test003/php.php3";
if(eregi("minudomeen", $http_referer)){
if(strlen($ip) < 6) OR (strlen($ip) > 15) {
print("All was correct!");
} else {
print("I don't think that you have such an IP address");
}
} else {
print("GO to back to the shadow!")
}
?>
<form method = "post" action = "php.php3">
<input type = "hidden" value = "k" name = "action"><BR><BR><BR>
Your IP plz: <center><font colour = "#669933"><input type= "text" name = "ip" size = "30"></font></center>
</form>
</BODY>
</HTML>

 

 (#451 2004-01-04 06:43:54) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

ahkorahil: first, why did you add the hidden value if you're not using it??

anyways, the problem with that line is that you shouldnt close the parenthises unless its the end of the if() statement, like so:

if(strlen($ip) < 6 OR strlen($ip) > 15) {

second, you missed a ; in the end of the print() command, just after that if :)

 

 (#453 2004-01-05 13:29:32) Post Reply

Ahkorahil
Need To Set


Enrolled: Oct 2003
Posts: 20
AP: 1

<HTML>
<HEAD>
<TITLE> 7. assignment</TITLE>
</HEAD>
<BODY>
<?php
$mydomain = "http://www.neti.ee";
if(eregi("$mydomain",$http_referer)) {
print("<a href=\$mydomain\">NETI</a>");
}else{
print("Your IP address is: $REMOTE_ADDR <br> And your browser is: $HTTP_USER_AGENT");
}
?>
</BODY>
</HTML>
// :P I should read assignments more careful, btw tnx to Quicksaver again :D

 

 (#718 2004-10-25 14:09:49) Post Reply

lestat
Need To Set


Enrolled: Jan 2004
Posts: 44
AP: 1

This is going well. I did NOT look at this forum 1 time :-)
Working URL: http://www.timslan.com/scripts...k7/wk7basic.php

<html>
<head>
<title>Week #7 BASIC ~ Lestat</title>
</head>
<body>
<?
// Check to see if user comes from a bookmark

// If they come from bookmark, deny access
if($HTTP_REFERER == ""){
print(
"<strong><h5><font color='red'>Sorry, you must come from the known domain(<a href = \"http://www.timslan.com/scriptskewl/index.html\">here</a>)</font></h5></strong>
<strong>Browser Type:</strong> $HTTP_USER_AGENT<br><br>
<strong>Connecting from IP address:</strong> $REMOTE_ADDR <html></body>"
);
}else{

// Check to see if they have come from my domain
$mydomain = "http://www.timslan.com/";
if(
eregi("$mydomain", $HTTP_REFERER)) {

// this visitor has come from my domain, so process the form
print("<h5>Welcome to the entrance point!</h5>
<strong>Youre browser type is:</strong> $HTTP_USER_AGENT<br><br>
<strong>You are connecting to me from:</strong> $REMOTE_ADDR<br><br>
Click <a href =
\"http://www.scriptschool.com\">here</a> to continue");

} else {

// This visitor has NOT come from my domain, so do NOT process the form
print("Sorry you can't use this page<br><br>You must come through the <a href=\"http://www.timslan.com/scriptskewl/index.html\">index</a> page.<br><br>
</body></html>"
);
exit();
}
}
?>







<pre>
</pre>
<br>
<iframe src='wk7basicsrc.php' width='100%' height='300'></iframe>
<br>

<a href='../index.html'>BACK</a>

</body>
</html>

 

 (#738 2004-11-12 17:48:27) Post Reply

Viat
Need To Set


Enrolled: Nov 2004
Posts: 2
AP: 1

Hey - I'm having a weird problem with HTTP_REFERER.



<?
echo $_SERVER['HTTP_REFERER']
?>




<?
echo $HTTP_REFERER
?>




give me an error message like
Notice: Undefined index: HTTP_REFERER in phptry.php on line 2.

Ideas anyone?

 

 (#783 2005-03-06 11:01:15) Post Reply

zman
Need To Set


Enrolled: Feb 2005
Posts: 15
AP: 1

My basic assignment #7"



<html>
<head>
<title>ScriptSchool.com Assignment 1</title>
</head>
<body bgcolor="666666">

<?php
/* ScriptSchool.com Assignment 7 (basic)
// Write a script to print the IP address if a surfer comes from
// a bookmark or type-in and show their browser type, and if the
// person comes from YOUR domain then print a clickable url.*/
print("<center><p><b>ScriptSchool.com Assignment 7 (basic)</b><br />
Write a script to print the IP address if a surfer comes from<br />
a bookmark or type-in and show their browser type, and if the<br />
person comes from YOUR domain then print a clickable url.</p></center>"
);

$mydomain = "((^http://)(www\.)?(garagechoppers\.com/).+)";
$mydomain1 = "(^http:\/\/(www\.)?garagechoppers\.com[\/])";

if(
eregi("$mydomain", $HTTP_REFERER))
{
// this visitor has come from my domain, so print a clickable URL
print("<center>\$HTTP_REFERER is $HTTP_REFERER<br /><a href=\"http://www.garagechoppers.com/learning_php/myassignments.html\">My Assignments</a></center>");
}
else
{
// this visitor has no HTTP_REFERER, so print their IP addr and browser type
if(!$HTTP_REFERER)
{
print(
"<center>\$HTTP_REFERER is $HTTP_REFERER<br />Your IP address is: $REMOTE_ADDR<br /><center> Your browser Type is: $HTTP_USER_AGENT</center>");
}
else
{
print(
"You did not type in this URL or come from a valid referring page.");
}
}

?>
</body>
</html>


 

 (#831 2005-06-12 09:38:59) Post Reply

vegyta2004
Need To Set


Enrolled: Apr 2005
Posts: 34
AP: 1

My week 7 assignment:
<? //week 7 basic assignment
echo"hello","<br>";
if($HTTP_REFERER=="")
{echo"you are not coming from my domain or you are using a bookmark";}
elseif($HTTP_REFERER=="http://www.vegyta.3x.ro")
{ECHO"welcome:","http://www.vegyta.3x.ro";}
else{echo"YOUR IP ADRESS IS:","$REMOTE_ADDR","<br>";
echo"YOUR BROWSER TYPE IS:"$HTTP_USER_AGENT";}
?>

 

 (#832 2005-06-13 09:36:16) Post Reply

vegyta2004
Need To Set


Enrolled: Apr 2005
Posts: 34
AP: 1

MY assignment reviewed

 

 (#833 2005-06-13 09:36:42) Post Reply

vegyta2004
Need To Set


Enrolled: Apr 2005
Posts: 34
AP: 1

MY assignment reviewed
<?

//week 7 basic assignment
echo"hello","<br>";
if($HTTP_REFERER=="")
{echo"YOUR IP ADRESS IS:","$REMOTE_ADDR","<br>";
echo"YOUR BROWSER TYPE IS:","$HTTP_USER_AGENT";}
elseif($HTTP_REFERER=="http://www.vegyta.3x.ro")
{ECHO"welcome:","http://www.vegyta.3x.ro";}
?>

 

 (#917 2005-12-31 02:42:58) Post Reply

Dylan
Need To Set


Enrolled: Dec 2005
Posts: 14
AP: 1

http://www.algore.org/~admin/week7.php



<html>
<body>
<?php

// Week 7 Assignment
// Write a script to print the IP address if a surfer comes from
// a bookmark or type-in and show their browser type, and if the
// person comes from YOUR domain then print a clickable url.

$mydomain = "http://www.algore.org/";

if (
eregi("$mydomain", $_SERVER['HTTP_REFERER'])) {
// this visitor has come from my domain
// NOTE for further development: should allow
// user to come with or without the www. I'm not
// certain the best way to code this without just
// making two variables and two if else statements
print("I see you're from around these parts... Feel free to <a href= \"secretpage.html\">click here.</a>");
} else {
echo
"You are not a local viewer. Your IP address is: " . $_SERVER['REMOTE_ADDR'] . " and your browser is: " . $_SERVER['HTTP_USER_AGENT'];
}

?>
</body>
</html>


 

 (#971 2006-03-20 22:10:54) Post Reply

Russell
Need To Set


Enrolled: Mar 2006
Posts: 19
AP: 1

i think that $HTTP_REFERER does not = http://www.yourdomain.com or even www.yourdomain.com, but rather www.yourdomain.com/pagename.php. and !$HTTP_REFERER only prevents bookmarkers and type-ins from accessing the page and allows other domains. because coming from another domain doesnt leave it blank.

so... heres what i came up with. if this is not correct please let me know



<?
$mydomain
="http://www.bigtitsfinder.com";
if(
ereg(".+mydomain.com.+", $HTTP_REFERER)){
print(
"everythings cool, you came from my domain.");
}else{
print(
"$REMOTE_ADDR $HTTP_USER_AGENT");
}
?>



this allows http://mydomain.com and http://www.mydomain but doesnt allow any other domain or bookmarkers and type-ins.

 

 (#972 2006-03-20 22:34:40) Post Reply

Russell
Need To Set


Enrolled: Mar 2006
Posts: 19
AP: 1

sorry, was so excited that i figured it out i didnt take the time to make it 100% (or my version of 100% anyways). and i dont have any non-adult domains so i wont be posting any working urls for now.


<?
if(eregi(".+mydomain.com.+", $HTTP_REFERER)){
print(
"everythings cool, you came from my domain. you can <a href=\"form.php\">click here</a> for the form.");
}else{
print(
"sorry, only surfers coming from one of my pages can go to the form.<br>your ip address is $REMOTE_ADDR<br>and your web browser is $HTTP_USER_AGENT");
}
?>



thanks
rl

 

 (#1000 2006-05-26 12:01:24) Post Reply

Andrius2a
Need To Set


Enrolled: May 2006
Posts: 6
AP: 1

<html>
<head>
<title>7 week Assignment</title>
</head>
<body>
<?php
//Geting domain value
$domain = 'http://$SERVER_NAME';
//Checking and access
if(eregi($domain, $HTTP_REFERER)) {
echo ("<a href='http://www.google.com'> www.google.com</a>"); }
else {
echo ("You are not from my domain, your IP is: <b>".$_SERVER['REMOTE_ADDR']."</b></br>");
echo ("And your are using: <b>".$_SERVER['HTTP_USER_AGENT']."</b>");}
?>

 

 

View Previous Thread
Print this page Print This Page

View Next Thread

School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store

Advertising | Link To Us | Privacy 
Copyright 2000-2002 Script School Productions / KMR Enterprises 
No part of this website may be reproduced, copied and/or distributed in any medium 
without express written permission