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

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

 (#17 2003-08-07 16:54:02) Post Reply

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

Week #9 TO-DO ASSIGNMENT: Write a script to enter urls using a form and save the unique urls in a cookie for the current browser session, and then display the urls that are saved using the same script as active hyperlinks opening in a target window. Write an administration script with the ability to modify and delete urls from the set cookies and protect access to this by using a script-based hard-coded password protection area. In the form portion where you modify the existing links be sure to prefill the input form with the existing url so it can more easily be modified.

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 the complete source code of the script in your post.

scriptname.php <-- script name

Good luck to you!

 

 (#260 2003-09-22 02:08:43) Post Reply

Shrek
Need To Set


Enrolled: Aug 2003
Posts: 33
AP: 1

My Week 9 Advanced To Do Assignment
http://members.lycos.co.uk/jef...an/class09a.php


<?
$urlarray
=array();
$array_url=$_COOKIE['array_url'];
$urlmemory=$_COOKIE['urlmemory'];
$action=$_REQUEST['action'];
$url1=$_REQUEST['url_input'];
$newurl=$_REQUEST['newurl_input'];
$user=$_REQUEST['user'];
$pass=$_REQUEST['pass'];

$days = 1;
$expires = time() + ($days * 86400);

$enable_modified=false;
if(
$user=='j' && $pass=='j')
{
$enable_modified=true;
}
switch (
$action)
{
case
'url1':

$days = 1;
$expires = time() + ($days * 86400);
if(
$urlmemory) // Cookie Present && url1)
{
if(
$url1)
{
if(
$url1=="RESET")
{
setcookie("urlmemory","",$expires);
setcookie("array_url",0,$expires);
echo (
"<br>COOKIES RESET --------------<br>");
} else
{
$array_url++;
setcookie("urlmemory", $urlmemory.",".$url1, $expires);
setcookie("array_url", $array_url,$expires);
}
}
}else
{
if(isset(
$url1))
{
if(
$url != "RESET" )
{
setcookie("urlmemory", $url1, $expires);
setcookie("array_url", 0,$expires);
}
}
}
break;
case
'delete':
if(
$urlmemory)
{
$urlarray=explode(",",$urlmemory);
$urlmemory="";
for(
$va_x=0;$va_x<=$array_url;$va_x++)
{
if(
$va_x!=$url1)
{
if(
$urlmemory)
{
$urlmemory=$urlmemory.",".$urlarray[$va_x];
}else
{
$urlmemory=$urlarray[$va_x];
}
}
}
setcookie("urlmemory",$urlmemory,$expires);
setcookie("array_url",$array_url-1,$expires);
echo (
"Link deleted!!!<br>");
echo (
"Press <a href='".$_SERVER['PHP_SELF']."'>HERE</a> to refresh<br>");
}
exit;
break;
case
'confirmed_modify':
{
$urlarray=explode(",",$urlmemory);
$urlmemory="";
for(
$va_x=0;$va_x<=$array_url;$va_x++)
{
if(
$va_x==$url1)
{
if(
$urlmemory)
{
$urlmemory=$urlmemory.",".$newurl;
}else
{
$urlmemory=$newurl;
}
}else
{
if(
$urlmemory)
{
$urlmemory=$urlmemory.",".$urlarray[$va_x];
}else
{
$urlmemory=$urlarray[$va_x];
}

}
}
setcookie("urlmemory",$urlmemory,$expires);
setcookie("array_url",$array_url,$expires);
echo (
"Link Modified!!!<br>");
echo (
"Press <a href='".$_SERVER['PHP_SELF']."'>HERE</a> to refresh<br>");
exit;
break;
}
case
'modified': // Here is Modify Zone
{
?>
<p>Modified your favorited URLs<p>

<form action= <? echo($_SERVER['PHP_SELF']); ?> method="post">
<input type="hidden" name="action" value="confirmed_modify" />
<input type="hidden" name="url_input" value=<? echo($url1); ?> />
<input type="text" name="newurl_input" size="30" value="" /><br>
<input type="submit" value="submit" />
</form>
<?
}

exit;
break;
default:
break;
}

if(
$urlmemory)
{
echo (
"<b> Your Favorite HYPERLINK MEMORY BY COOKIES </b><p>");
echo (
"No. URL<p>");
$urlarray=explode(",",$urlmemory);
for(
$va_x=0;$va_x<=$array_url;$va_x++)
{
$displayurl=$urlarray[$va_x];
echo ((
$va_x+1)."------------- <a href='http://".$displayurl."'>".$displayurl."</a>");
if(
$enable_modified)
{
echo (
" -------------- ");
echo (
"(<a href='".$_SERVER['PHP_SELF']."?action=delete&url_input=".$va_x."'>DELETE</a>");
echo (
") / (");
echo (
"<a href='".$_SERVER['PHP_SELF']."?action=modified&url_input=".$va_x."'>MODIFIED</a>)");
}
echo (
"<br>");

}
}

?>
<HTML>
<BODY>
<p>Enter Your Favorite URLs<p>
<form action= <? echo($_SERVER['PHP_SELF']); ?> method="post">
<input type="hidden" name="action" value="url1" />
<input type="text" name="url_input" size="30" value="" /><br>
<br>
<br>
Input Username or Passwor to modified the link<br>
<input type="text" name="user" size="30" value="" /><br>
<input type="password" name="pass" size="30" value="" /><br>
<input type="submit" value="submit" />
</form>
<I> Enter "RESET" in URL box To Reset COOKIES </I><P>
<I> If you can't see your favorite URL, press SUMIT again to refresh. </I><P>

</BODY>
</HTML>


 

 (#339 2003-10-29 05:13:22) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

finnaly! thanks to logspirit for helping me with that warning :)


assignement9advanced.php

<? ob_start(); ?>
<html>
<head><title>URL memorizing form</title></head>
<body>
<?
global $PHP_self;
$name = "Quick";
$pass = "saver";

if(
$adminaction == "true") {
if(
ereg($name, $username) && ereg($pass, $password)) {
setcookie("admin", "true");
$adminaction = "false";
header("Location: $SCRIPT_NAME"); } else { print("<font color=\"ff0000\"><b>Error:</b> Invalid username/password.</font><br><br>"); } }

if(
$admin == "error") {
setcookie("admin", "ok");
print(
"<font color=\"#ff0000\"><b>Error:</b> No stored Urls to modify or delete.</font><br><br>"); }

if(
$action == "added") {
$addedurl = "http://$added";

if(!
$urls) {
setcookie("urls", $addedurl);
$action = "done";
header("Location: $SCRIPT_NAME");
} else {
$savedurls = explode("§", $urls);
$howmanyurls = count($savedurls);
for(
$e = 0; $e < $howmanyurls; $e++) {
if(
eregi("$addedurl", $savedurls[$e])) { $alreadysaved = "true"; } }
if(!
$alreadysaved) {
setcookie("urls", $urls."§".$addedurl);
$action = "done";
header("Location: $SCRIPT_NAME");
} else { print(
"<font color=\"ff0000\"><b>That URL was already saved during this browser section.</b></font><br><br>"); } } }

if(
$admin == "true") {
if(
$urls) { include("administrator9advanced.php"); } else {
setcookie("admin", "error");
header("Location: $SCRIPT_NAME"); } } else {

if(
$urls) {
$showurls = explode("§", $urls);
$howmany = count($showurls);
print(
"<b>Stored URLs</b><br><br>");

for(
$a=0; $a < $howmany; $a++) {
print(
"<a href=\"$showurls[$a]\" target=\"new window\">$showurls[$a]</a><br>"); }
print(
"<br><br>"); } }

ob_end_flush();
?>

<table>
<tr><td><form method="post" action="<? $PHP_self ?>">
<b>Insert your URL here:</b><br><br>
<input type="hidden" name="action" value="added"> <A HREF="http://<input" TARGET=_blank>http://<input</A> type="text" name="added" size="50">
<input type="submit" value="Add URL"><br>
<font size="2">(Please be aware of putting a correct url address as the script will not check if it is valid.)</font>
</form></td></tr>

<?
if($admin != "true") {
print(
"<tr><td><br><form method=\"post\" action=\"$PHP_self\">
<b>Administrator mode:</b><br>
<input type=
\"hidden\" name=\"adminaction\" value=\"true\"><br>
<input type=
\"text\" name=\"username\" size=\"15\"><br>
<input type=
\"password\" name=\"password\" size=\"15\"><br>
<input type=
\"submit\" value=\"Login\"></form></td></tr>"); } ?>
</table>
</body>
</html>

administrator9advanced.php

<? ob_start(); ?>
<html>
<head><title><? if($action) { print("$action Url"); } else { print("URL memorizing form - Administrator mode"); } ?></title></head>
<body>
<?
global $PHP_self;
$dellink = "/administrator9advanced.php?action=Delete&url=";
$modlink = "/administrator9advanced.php?action=Modify&url=";
$adminurls = explode("§", $urls);
$howmanyurls = count($adminurls);

if(
$action == "Modify") {
print(
"<form method=\"post\" action=\"$PHP_self\">
<input type=
\"hidden\" name=\"urlaction\" value=\"$action\">
<input type=
\"hidden\" name=\"action\" value=\"done\">
<input type=
\"text\" name=\"address\" value=\"$adminurls[$url]\" size=\"50\">
<input type=
\"submit\" value=\"$action Url\"></form>");
ob_end_flush();
exit(); }

if(
$action == "Delete") {
print(
"$adminurls[$url]");
print(
"<form method=\"post\" action=\"$PHP_self\">
<input type=
\"hidden\" name=\"urlaction\" value=\"$action\">
<input type=
\"hidden\" name=\"action\" value=\"done\">
<input type=
\"submit\" value=\"$action Url\"></form>");
ob_end_flush();
exit(); }

if(
$urlaction) {
if(
$urlaction == "Modify") {
for(
$a = 0; $a < $howmanyurls; $a++) {
if(
$url != $a) {
if(!
$urlstobeset) { $urlstobeset = $adminurls[$a]; } else { $urlstobeset = $urlstobeset."§".$adminurls[$a]; } } else {
if(!
$urlstobeset) { $urlstobeset = $address; } else { $urlstobeset = $urlstobeset."§".$address; } } } }

if(
$urlaction == "Delete") {
for(
$a = 0; $a < $howmanyurls; $a++) {
if(
$url != $a) {
if(!
$urlstobeset) { $urlstobeset = $adminurls[$a]; } else { $urlstobeset = $urlstobeset."§".$adminurls[$a]; } } } }

setcookie("urls", $urlstobeset);
header("Location: assignement9advanced.php"); }
ob_end_flush();

$showurls = explode("§", $urls);
$howmany = count($showurls);
print(
"<b>Stored URLs</b><br><br>");
print(
"<table>");

for(
$url=0; $url < $howmany; $url++) {
print(
"<tr><td><a href=\"$showurls[$url]\" target=\"new window\">$showurls[$url]</a></td>
<td>(<a href=
\"$modlink$url\" onMouseOver=\"window.status='Modify the link\"
onMouseOut=
\"window.status='';\">modify</a>/<a href=\"$dellink$url\" onMouseOver=\"window.status='Delete the link\"
onMouseOut=
\"window.status='';\">delete</a>)</td></tr>"); }

print(
"</table>");
print(
"<br><br>");
?>
</body>
</html>


working url

 

 (#369 2003-11-05 09:32:02) Post Reply

Dest
Need To Set


Enrolled: Oct 2003
Posts: 18
AP: 1

Im going to be third who makes it :) cool :)

i made 2 scripts. enter page (where you enter pass) and main script.

login: dest
pass: script

enter page: http://tts.lt/~sir/scripts/week9adventer.php

main script: http://tts.lt/~sir/scripts/week9adv.php

main script code:


<?

$urls
=array($url1, $url2, $url3);

if(
$formcookie=="reset")

{
setcookie("urlcook1");
setcookie("urlcook2");
setcookie("urlcook3");
}

if(
$form=="done")
{
setcookie(urlcook1, $urls[0], 8000000);
setcookie(urlcook2, $urls[1], 8000000);
setcookie(urlcook3, $urls[2], 8000000);
}

?>

<html>
<body>

<form method=POST action=<?$PHP_SELF?>>
<input type=hidden name=form value=done>
URL 1:<input type=text name=url1 value="<?print("$urlcook1");?>" size=40> <? if($urlcook1) {print("<a href=$urlcook1 target=_blank>$urlcook1</a>"); } ?> <br>
URL 2:<input type=text name=url2 value="<?print("$urlcook2");?>" size=40> <? if($urlcook2) {print("<a href=$urlcook2 target=_blank>$urlcook2</a>"); } ?> <br>
URL 3:<input type=text name=url3 value="<?print("$urlcook3");?>" size=40> <? if($urlcook3) {print("<a href=$urlcook3 target=_blank>$urlcook3</a>"); } ?> <br><br>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="55%" >
<tr>
<td width="15%"><center><input type=submit value=Submit></form>

<form>
<form method=POST action=<?$PHP_SELF?> >
<input type=submit value=Refresh>
</form>
<form method=POST action=<?$PHP_SELF?> >
<input type=hidden name=formcookie value=reset>
<input type=submit value=Reset>
</form></center>
</td>
<td width="40%" valign="top">Write 3 your favourite url's. After each action (reset, submit) dont forget to click refresh. If you have written urls already, you can modify them. If you dont like url's and dont want to modify them you can write url's again by pressing Reset (and then refresh)<br>
<font color=red size=2><b> <br>Note: </b></font><font size=2> Make sure that cookies are enabled. Script will not work without cookies enabled.</font></td>
</tr>
</table>


 

 (#390 2003-11-19 04:37:07) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

ok, im changing hosts and thats why ive been a lil delayed with assignement 10

on my new host register_globals are off so i was updating all my scripts to work with that, but this one either needs something more or i just dont get what wrong. the code is basically the same, just added the following $trings to the beggining of each:


assignement9advanced.php

<? ob_start(); ?>
<html>
<head><title>URL memorizing form</title></head>
<body>
<?
global $PHP_self;
$SCRIPT_NAME = $_SERVER["SCRIPT_NAME"];
$admin = $_COOKIE["admin"];
$urls = $_COOKIE["urls"];
$username = $_POST["username"];
$password = $_POST["password"];
$added = $_POST["added"];
$adminaction = $_POST["adminaction"];
$action = $_POST["action"];
$name = "Quick";
$pass = "saver";

administrator9advanced.php
<? ob_start();
$action = $_REQUEST["action"]; ?>
<html>
<head><title><? if($action) { print("$action Url"); } else { print("URL memorizing form - Administrator mode"); } ?></title></head>
<body>
<?
$urls
= $_COOKIE["urls"];
$urlaction = $_POST["urlaction"];
$dellink = "http://quicksaver.beigetower.org/php_assignements/administrator9advanced.php?action=Delete&url=";
$modlink = "http://quicksaver.beigetower.org/php_assignements/administrator9advanced.php?action=Modify&url=";
$adminurls = explode("§", $urls);
$howmanyurls = count($adminurls);



the rest is exactly the same. I dunno what im missing, if i enter the admin mode it doesnt show the urls on the cookie! help?!
its here

 

 (#399 2003-11-22 04:00:38) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

never mind, fixed it (dunno how but fixed it :))

 

 (#842 2005-06-23 10:45:37) Post Reply

vegyta2004
Need To Set


Enrolled: Apr 2005
Posts: 34
AP: 1

Week9_advanced.php:

<?
$valid_username="vegyta";
$valid_password="seling";
if(($username==$valid_username)and($password==$valid_password))
{ header("Location:week9_advanceds.php");}
else{echo"Invalid username of password";}
?>
<HTML>
<BODY>
<br><br><br><br>
<form method="POST" action="<?PHP_SELF?>">
USERNAME:<input type="text" name="username"><br>
PASSWORD:<input type="password"name="password"><br>
<input type="submit"value="LOG IN"><br>
<input type="reset"value="Reset data">
</BODY>
</HTMl>

File week9_advanceds:
<HTML>
<BODY> WELCOME ADMIN VEGYTA!<br>
<form method="POST" action="<?PHP_SELF?>">
new url1:<input type="text"name="modified_url_1"><br>
new url2:<input type="text"name="modified_url_2"><br>
new url 3:<input type="text"name="modified_url_3"><br>
DELETE URL:<input type="checkbox" name="deleted_url"value="true"><br>
<input type="submit"name="Send Option">
<br>
</BODY>
</HTML>
<?
if($deleted_url=="true")
{
setcookie("cookie_set","",time()-4600);
echo"url's and cookie deleted";}

else{
$url_modified=array($modified_url_1,$modified_url_2,$modified_url_3);
$initial=unserialize(stripslashes($cookie_set));
$new_value=serialize($url_modified); $cookie_set=$new_value;
echo"valorile initiale sunt:","<BR>";
foreach($initial as $key=>$value)
{echo"$key:$value","<br>";}
echo"valorile modificate sunt:","<br>";
$final=unserialize(stripslashes($cookie_set));
foreach($final as $key=>$value)
echo"$key=>$value","<br>";}

?>

 

 (#904 2005-12-19 10:53:39) Post Reply

Gixboy
Need To Set


Enrolled: Nov 2005
Posts: 7
AP: 1

Alright guys, this lesson got me mroe than any before, because it seriously calls for remembering everything you were taught, plus going out and doing some PHP learning on your own. It's a much more creative and thus individual assignment.

Some things about my script that you may want to know. First off, IT DOES WORK WITH PHP5. I don't think any of the other examples do. Second, my script limita the user to 15 favorites, but you can easily change that by going through all the loops and changing "$n < 15" to whatever number you want. Finally, there are two pages only because when you set a cookie, the page must refresh before you can see it. If you refresh the page though, it remembers not only the cookie, but also you submitting the url form. the resulting page will have the new link displayed, but it will also have an ERROR message saying you altready have that link. To avoid getting this spam error message, a second page is used called "refresher" in which the only code is a header leading to the HTTP_REFERER... in other words, right back where you started except without the error.

Anyway, now you know how it works, but now also you can how it works :) This took me DAYS to perfect, so I hope you guys like it!!



<?
ob_start
();
global
$PHP_SELF;

$user="Gixboy";
$pass="modpass";
$day=730;
$expires=(time()+($day * 86400));
$empty1="Still Available for Use";
$error1="ERROR: You must provide a Link Number.";
$error2="ERROR: You must provide a valid URL.";
$error3="ERROR: You have provided an invalid Username and/or Password.";
$error4="ERROR: You already have that URL saved in one of the links.";
if(
$_POST['del_action']=="true") {
for(
$t=0; $t < 15; $t++) {
if(
$_POST[$t]=="delete") {
setcookie("urls[$t]",$empty1,$expires); } }
header("Location: /refresher.php");
}
if(
$_POST['action']=="true") {
if(
eregi("^(http://)?([a-zA-Z0-9\-]+)(\.)([a-zA-Z0-9\.\-]+)([^[:space:]]*)$",($_POST['url']))) {
$url_real=TRUE; }
if(
$url_real==TRUE) {
if(
$_POST['save_to_num']!="error") {
if(!
$_COOKIE['urls']) {
for(
$i=0; $i < 15; $i++) {
setcookie("urls[$i]",$empty1,$expires);
} } else {
$m=($_POST['save_to_num'] - 1);
for(
$i=0; $i < 15; $i++) {
if(
$_POST['url']==$_COOKIE['urls'][$i]) { $used="YES"; }
}
if(
$used!="YES") {
setcookie("urls[$m]",$_POST['url'],$expires);
header("Location: /refresher.php"); }
} } }
}
?>

<HTML>
<head><title>Your Online Favorites</title>
</head>
<BODY>

<center><b><u><font size="+1">Favorites Uploads / Links Page
</font></b></u><br>
<i>Only a Moderator can remove links from your list.<br>
You can <u>replace</u> as many as you want though.</i></center>
<br><br>
<table width="100%">
<tr><td>
<table>
<tr><td valign=top>
<center><b><u>Upload URL</b></u><br><i>Include <A HREF="http://</i></center>" TARGET=_blank>http://</i></center></A>
<br>

<?
if($_POST['action']=="true") {
if(
$url_real!=TRUE) {
print(
"$error2"); ?><br><?
}
if(
$_POST['save_to_num']=="error") {
print(
"$error1"); ?><br><?
}
if(
$used=="YES") { print("$error4"); ?><br><?
}
}
?>

<FORM method="POST" action="<? $PHP_SELF ?>">
<input type="hidden" name="action" value="true">
<b>URL:</b> <input type="text" name="url" size="30">
to <b>Link #:</b>
<select name="save_to_num">
<option selected value="error"> </option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
<option value="6">Six</option>
<option value="7">Seven</option>
<option value="8">Eight</option>
<option value="9">Nine</option>
<option value="10">Ten</option>
<option value="11">Eleven</option>
<option value="12">Twelve</option>
<option value="13">Thirteen</option>
<option value="14">Fourteen</option>
<option value="15">Fifteen</option>
</select>
<br>
<input type="submit" value="Upload your Link Now!">
</FORM>
</td></tr>
<tr>
<td>
<?
if($_POST['mod_action']=="true") {
if(
$_POST['username']!=$user OR $_POST['password']!=$pass) {
print(
"$error3"); } }
if(
$_POST['mod_action']=="true" && $_POST['username']==$user && $_POST['password']==$pass)
{
$q=YES; }
if(
$q!=YES) {
?>

<br>
<center>
<center><b><u>Moderator Login</b></u></center>
<center><table><tr><td>
<FORM method="POST" action="<? PHP_SELF ?>">
<input type="hidden" name="mod_action" value="true">
<tr><td>USERNAME: </td><td><input type="text" name="username" size="15"></td></tr>
<tr><td>PASSWORD: </td><td><input type="password" name="password" size="15"></td></tr>
</table>
<center><input type="submit" value="Login" size="7"></center>
</FORM>
<? } ?>
</td></tr></table>
</td>
<td valign=top>
<center><b><u>Your Links:</b></u></center>
<br><br>

<?
if($_POST['mod_action']=="true" && $_POST['username']==$user && $_POST['password']==$pass) {
?>
<FORM method="POST" action="<? $PHP_SELF ?>">
<input type="hidden" name="del_action" value="true">
<?
for($r=1; $r <= 15; $r++) {
$t=($r - 1);
$link=$_COOKIE['urls'][$t]; ?><table><?
if($link!=$empty1) {
?>
<tr><td>
<input type="checkbox" name="<? echo "$t" ?>" value="delete"> </td><td><b>Link <? print("$r"); ?>:</b>
<a href="<? echo "$link" ?>"><? print("$link"); ?></a></td></tr>
<?
} else {
?>
<tr><td>
<input type="checkbox" name="<? echo "$t" ?>" value="delete"> </td><td><b>Link <? print("$r"); ?>:</b>
<? print(" "); ?></td></tr>
<?
} }
?>
</table>
<input type="submit" value="Delete Selected" size="12.5">
</table>
</FORM>
<? } else {
for(
$r=1; $r <= 15; $r++) {
$t=($r - 1);
$link=$_COOKIE['urls'][$t];
if(
$link!=$empty1) {
?><b>Link <? print("$r"); ?>:</b>
<a href="<? echo "$link" ?>"><? print("$link"); ?></a><br>
<?
} else {
?><b>Link <? print("$r"); ?>:</b> <? print(" "); ?><br>
<?
} } }
?>

</td></tr>
</table>

</BODY>
</HTML>



<?

/* This site's purpose is to refresh a page
unnoticeably. We need to refresh,
otherwise the new cookies will not be
displayed. */

header("Location: $_SERVER[HTTP_REFERER]")
?>



 

 (#905 2005-12-23 15:16:10) Post Reply

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

Gixboy - you did a really nice job here. I must admit that I was surprised to see the qualiy of your work. Keep at it.

BTW, you are welcome back in the chatroom as long as you can not interupt and be rude to those who are trying to help you.

 

 (#906 2005-12-24 01:58:30) Post Reply

Gixboy
Need To Set


Enrolled: Nov 2005
Posts: 7
AP: 1

thanks, but I was being naive when I said I "perfected" it. The eregi() web url function has a ? after the ^(http://) that should not be there. The way it is now, you can add something like "gixboy.com" instead of "http://gixboy.com" and that will ultimately make the link lead to http://gixboy.com/gixboy.com which, of course, doesn't exist.

Also, if you put that code into a browser, you'll notice that the first time you use the script, nothing will happen - you must use it again before it wakes up and realizes that it should be doing something. That can easily be fixed by just moving the if(!$_COOKIE['urls']) conditional ahead of if($_POST['action']=="true") conditional.

You need to make those two changes for the code to work 100% properly. I did not realize either of those two because, respectively, I tested the false url by randomly typing in letters or leaving it blank, and I had been testing so much that the cookie was set, so I never retested the first time. It wasn't until I uploaded it onto my domain and tried to access it from another desktop that I realized what was happening.

Besides those two little things, there are things that can be done to make the code shorter, that, after writing the thing for days, I was too lazy to go back and do. But it still works nonetheless.

Thanks TD for your enthusiasm in the quality of my script, but for now I'm gonna fly solo when it comes to programming. I'll use the script school when I need to, and I'll post the assignments here like I have been, but I won't be asking questions in the chat anymore. As we saw today, at the point that I'm getting to, it's hard to phrase both a question and an answer in a way that both parties can understand. Between the time it takes to decipher one another's thoughts and to argue, I probably could have figured the problem out on my own by then.

~ Gix

 

 (#907 2005-12-28 15:10:39) Post Reply

lestat
Need To Set


Enrolled: Jan 2004
Posts: 44
AP: 1

As far as 'nothing happening' goes, you may want to look back to week #8, where headers and redirection were covered.


<?php
if($this){
header("Location: $PHP_SELF");
}
?>




But I'm sure you would have "figured that on your own"...

 

 (#979 2006-03-23 03:35:52) Post Reply

Russell
Need To Set


Enrolled: Mar 2006
Posts: 19
AP: 1

this was a bugger :) thanks lestat for the live help. again, cant post a working url because i dont have any non-adult domains. and its on a server with php 4.4.0 not 5.0 :/ i guess theres things that will need to be changed when my server upgrades its php. ill figure those out when that happens.


<?
// if sent from set cookies form or re-write cookies admin area form - set the cookies.
if($urlform=="true" OR $urlform2=="true"){
$days = 1;
$expires = time()+($days * 86400);
if(
$url1){
setcookie(link1,$url1,$expires);
}
if(
$url2){
setcookie(link2,$url2,$expires);
}
if(
$url3){
setcookie(link3,$url3,$expires);
}
// if sent from the original set urls form re-direct to display links page with admin page link.
if($urlform=="true"){
header("Location: $PHP_SELF?cookiesset=true");
// if sent from admin page re-write cookies go to display links with start over link.
}elseif($urlform2=="true"){
header("Location: $PHP_SELF?cookiesset=false");
}
// display url's with proceed to admin page link.
}elseif($cookiesset=="true"){
if(
$link1){
print(
"URL 1: <a href=\"$link1\">Link 1</a><br>\n");
}
if(
$link2){
print(
"URL 2: <a href=\"$link2\">Link 2</a><br>\n");
}
if(
$link3){
print(
"URL 3: <a href=\"$link3\">Link 3</a><br>\n");
}
print(
"Cookies set - <a href=\"$PHP_SELF?adminpage=true\">proceed to admin</a>?");
// display url's with start over page link.
}elseif($cookiesset=="false"){
if(
$link1){
print(
"URL 1: <a href=\"$link1\">Link 1</a><br>\n");
}
if(
$link2){
print(
"URL 2: <a href=\"$link2\">Link 2</a><br>\n");
}
if(
$link3){
print(
"URL 3: <a href=\"$link3\">Link 3</a><br>\n");
}
print(
"Cookies set - <a href=\"$PHP_SELF\">start over</a>?\n");
// show user and pass form to enter admin area.
}elseif($adminpage=="true"){
print(
"
<form method=\"post\" action=\"/testing/lesson9.php\">\n
<input type=\"hidden\" name=\"adminform\" value=\"true\">\n
Username: <input type=\"text\" name=\"username\"><br>\n
Password: <input type=\"text\" name=\"password\"><br>\n
<input type=\"submit\" value=\"Submit\">\n
</form>\n"
);
// admin area for editing the cookies.
}elseif($adminform=="true"){
$user="user";
$pass="pass";
if(
$username==$user && $password==$pass){
print(
"Edit the cookie urls here.<br>\n
<form method=\"post\" action=\"$PHP_SELF\">\n
<input type=\"hidden\" name=\"urlform2\" value=\"true\">\n"
);
if(
$link1){
print(
"
URL 1: <input type=\"text\" name=\"url1\" value=\"$link1\" size=\"40\"><br>\n"
);
}
if(
$link2){
print(
"
URL 2: <input type=\"text\" name=\"url2\" value=\"$link2\" size=\"40\"><br>\n"
);
}
if(
$link3){
print(
"
URL 3: <input type=\"text\" name=\"url3\" value=\"$link3\" size=\"40\"><br>\n"
);
}
print(
"<input type=\"submit\" value=\"Submit\">\n
</form>\n"
);
}else{
print(
"username and password are incorrect.<br>\n
please use your back button and try again.\n"
);
}
// if no other elseifs or ifs match show the original enter urls form.
}else{
print(
"
<form method=\"post\" action=\"$PHP_SELF\">\n
<input type=\"hidden\" name=\"urlform\" value=\"true\">\n
<h2>Cookie Setting & Editing With Admin Area Script</h2>\n
Write your 3 urls below that will be set into cookies.<br>\n
URL 1: <input type=\"text\" name=\"url1\" size=\"40\"><br>\n
URL 2: <input type=\"text\" name=\"url2\" size=\"40\"><br>\n
URL 3: <input type=\"text\" name=\"url3\" size=\"40\"><br>\n
<input type=\"submit\" value=\"Submit\">\n
</form>"
);
}
?>



 

 (#980 2006-03-23 03:37:37) Post Reply

Russell
Need To Set


Enrolled: Mar 2006
Posts: 19
AP: 1

p.s. i made it an all-in-one script :P

 

 

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