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

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

 (#16 2003-08-07 16:52:36) Post Reply

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

Week #9 Basic 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.

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!

 

 (#99 2003-08-27 13:00:56) Post Reply

Sk8rRIMuk
Need To Set


Enrolled: Aug 2003
Posts: 39
AP: 1

I enjoyed this one :P

My working example is at:
http://www.katikai.com/ee/assi...0Assignment.php

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

Finally heres my code =):


<?php
//Set the variables for the expire date
$days=7;
$expires=time()+($days*86400);
//Set the the three cookie entries based on what is submitted
if($cookieurl0){
setcookie("cookieurl0",$url0,$expires);
}else{
setcookie("cookieurl0",$expires);
}
if(
$cookieurl1){
setcookie("cookieurl1",$url1,$expires);
}else{
setcookie("cookieurl1",$expires);
}
if(
$cookieurl2){
setcookie("cookieurl2",$url2,$expires);
}else{
setcookie("cookieurl2",$expires);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Week #9 Basic To-Do Assignment</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
//Check to see if the form has been submitted yet
if($stored=='true'){
//If it has frint the URL's from the cookies
print("<p>Your 3 URL's are:<br /><br /><a href="$url0" target="_blank">$url0
</a><br/><ahref="
$url1" target="_blank">$url1</a><br/><ahref="$url2"
target="
_blank">$url2</a></p>");
}else{
//If it hasn't display the form
?>
<p>Please enter the desired website address to be stored via cookie:</p>
<form method="post" action="<?php$PHP_SELF?>">
<input type="hidden" name="stored" id="stored" value="true" />
Website One: <input type="text" name="url0" id="url0" /><br />
Website Two: <input type="text" name="url1" id="url1" /><br />
Website Three: <input type="text" name="url2" id="url2" /><br />
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</form>
<?php}?>
<font style="font-size: 10px;"><b>Caution:</b>This page uses cookies to display
your chossen websites, you must have cookies enable for this page to be
displayed properly, thankyou.</font>
</body>
</html>


 

 (#100 2003-08-27 13:02:10) Post Reply

Sk8rRIMuk
Need To Set


Enrolled: Aug 2003
Posts: 39
AP: 1

Correction:

//If it has frint the URL's from the cookies

thats meant to be print not frint :S so its:

//If it has print the URL's from the cookies

 

 (#246 2003-09-18 07:54:18) Post Reply

Shrek
Need To Set


Enrolled: Aug 2003
Posts: 33
AP: 1

A very difficult Assignment
http://members.lycos.co.uk/jef...wan/class09.php



<?
$urlarray
=array();
$array_url=$_COOKIE['array_url'];
$urlmemory=$_COOKIE['urlmemory'];
$action=$_REQUEST['action'];
$url1=$_REQUEST['url_input'];
if(
$action=='url1') // INPUT FROM FORM
{
$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);
}
}
}
}
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></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>
<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>


 

 (#306 2003-10-10 12:19:57) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

sorry my lil lack of activity... been a lil adicted to counter strike (its awesome ;))

anyways i still have my week 8 advanced problem and now i have another problem on this one, i wont be making any more scripts untill i fix both of them, so i kinda need help on them

ok, here's my code


<html>
<head>
<title>URL memorizing form</title>
</head>
<body>

<?
global $PHP_self;
$names = $_COOKIE["names"];
$urls = $_COOKIE["urls"];
$descriptions = $_COOKIE["descriptions"];
$days = 3;
$expires = time() + $days * 86400;

if(
$action == "added") {
if(
$name == "RESET") {
setcookie("names");
setcookie("urls");
setcookie("descriptions");
print(
"<b>All links were reseted</b><br><br>"); } else {
if(
$name && $url && $comments) {
setcookie("names", $names." § ".$name, $expires);
setcookie("urls", $urls." § ".$url, $expires);
setcookie("descriptions", $descriptions." § ".$comments, $expires);
} else { print(
"Please hit \"back\" on your browser and fill in all of the fields!"); } } }

if(
$names != "") {
$showname = explode(" § ", $names);
$showurl = explode(" § ", $urls);
$showcomments = explode(" § ", $descriptions);
$number = count($names)-1;
print(
"<b>Stored links</b><br><br>");
for(
$a=0; $a<$number; $a++) {
print(
"<a href=\"$showurl[$a]\">$showname[$a]</a> - $showcomments[$a] <br>");
} } else { print(
"<b>No stored links.</b><br><br>"); }
?>

<form method="post" action="<? $PHP_self ?>">
<input type="hidden" name="action" value="added">
<input type="text" name="name" value="no name" size="50"> Name the URL<br>
<input type="text" name="url" size="50"> URL<br>
<input type="text" name="comments" value="no comments" size="50"> Brief description of the url<br>
<input type="submit" value="add URL">
</form>
<br><br>
<b>Instructions</b><br>
1. You have to enable cookies for this script to work.<br>
2. Make sure you fill in all the fields, if dont wish to add any name or comments, then just leave as it is (e.g."no name").<br>
3. To reset your cookies, input "RESET" on the name field and click "add url".<br>
4. Make sure you visit this page every 3 days or your cookies will not be validated the next time you access this page (your saved urls will be deleted), so visit this page once each 3 days so you dont lose your saved urls.<br>
5.Make sure you dont use the "§" symbol in any of the fields or your cookies will get a bug that will prevent the script of working correctly.<br>
</body>
</html>


so basically this happens on my online server. could that error be because of some limitation of the server or something because if i try that code here (localhost) it doesnt write the urls on the code

so anyone help... oh and if i seem to be a lil inactive on the next times, im not dead :P just playin CS

 

 (#329 2003-10-23 17:18:56) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

well finnaly working, but this one beated me out, specially the part where it says "save only the UNIQUE urls" :)


<?
global $PHP_self;

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(
$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>"); } }
?>

<form method="post" action="<? $PHP_self ?>">
<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">
</form>

Please be aware of putting a correct url address as the script will not check if it is valid.


working url

 

 (#545 2004-03-10 14:35:53) Post Reply

Cyb
Need To Set


Enrolled: Feb 2004
Posts: 6
AP: 1

It seems not many people are posting here.
I think though this is a very great course (best I could find) and I do want to post my script because the scripts posted here are 100% correct according to the assignment.

It took me much effort ;) but eventually this should be right. It checks each url on being unique (incasesensitive), adds http:// only if it wasnt there yet, can enter as much urls as the cookie size limit lets you etc. etc. ow and it doesnt use fuctions not described in the courses 1 to 9 yet. :)




<?php
if ($form == filled) {
$expires = time()+86400;
if (!
eregi(^http://, $url)) {
$url = <A HREF="http://;" TARGET=_blank>http://;</A>
}
if (
$links) {
$links_array = explode(|, $links);
for (
$x=0; $x<count($links_array); $x++) {
if (
eregi($links_array[$x], $url)) {
$unique = no;
}
}
if (
$unique != no) {
setcookie(links, $links|$url , $expires);
}
else {
$error_msg = You may only enter unique url's;
}
}
else {
setcookie(links,$url, $expires);
}
}
?>
<html>
<head>
<title>Cookie urls</title>
</head>

<body>
<?php
if ($links) {
for ($i=0; $i<count($links_array); $i++) {
print (<a href=$links_array[$i] target=_blank>$links_array[$i]</a><br>);
}
}
?>
<p>
<form>
Enter url here:<br>
<input type=text name=url><br>
<input type=hidden name=form value=filled>
<input type=submit value=OK>
</form>
<p>
<?php echo $error_msg; ?>
</body>
</html>



 

 (#546 2004-03-10 14:38:55) Post Reply

Cyb
Need To Set


Enrolled: Feb 2004
Posts: 6
AP: 1

blah why each time that problem with the " " missing :(.
mmm lets try again... this is the working url btw http://www.members.lycos.nl/tw...ieurlscript.php



<?php
if ($form == "filled") {
$expires = time()+86400;
if (!
eregi("^http://", $url)) {
$url = "http://$url";
}
if (
$links) {
$links_array = explode("|", "$links");
for (
$x=0; $x<count($links_array); $x++) {
if (
eregi($links_array[$x], $url)) {
$unique = "no";
}
}
if (
$unique != "no") {
setcookie("links", "$links|$url" , $expires);
}
else {
$error_msg = "You may only enter unique url's";
}
}
else {
setcookie("links",$url, $expires);
}
}
?>
<html>
<head>
<title>Cookie urls</title>
</head>

<body>
<?php
if ($links) {
for (
$i=0; $i<count($links_array); $i++) {
print (
"<a href=\"$links_array[$i]\" target=\"_blank\">$links_array[$i]</a><br>");
}
}
?>
<p>
<form>
Enter url here:<br>
<input type="text" name="url"><br>
<input type="hidden" name="form" value="filled">
<input type="submit" value="OK">
</form>
<p>
<?php echo "$error_msg"; ?>
</body>
</html>


 

 (#742 2004-11-15 17:44:59) Post Reply

lestat
Need To Set


Enrolled: Jan 2004
Posts: 44
AP: 1

By looking at the posted examples, I'm not quite sure if I've done whats been asked for here. Working url - http://tdurl.com//m

<?
/* [HEADER & COOKIE HANDELING] */
if($in == clear){
setcookie("sitevisits"); // Clear Sitevisits Cookie
setcookie("urlcookie"); // Clear url Cookie
header("Location: <A HREF="http://www.timslan.com/scriptskewl/week9/wk9basic.php");" TARGET=_blank>http://www.timslan.com/scripts...k9basic.php");</A>
}else{
$days = 1; // This Part from TD's Example in tutorial
$expires = time()+($days * 86400); // Setting Expiration Date on Cookie
if($sitevisits) {
$sitevisits++;
// now we need to set the cookie with the new value
setcookie("sitevisits", $sitevisits, $expires);
} else {
// this must be a new visitor, so set initial cookie
setcookie("sitevisits", 1, $expires);
}
//closed
}


/* [ SET URL COOKIE ] */
setcookie("urlcookie[0]",$_POST['url1']);
setcookie("urlcookie[1]",$_POST['url2']);
setcookie("urlcookie[2]",$_POST['url3']);
?>





<html>
<head>
<title>Week #9 BASIC ~ Lestat</title>
<link rel="stylesheet" type="text/css" href="/css/scriptskewl.css">
</head>

<body>


<?
print("Thank you for visiting this page $sitevisits times!<br>");
print(
"<a href="http://www.timslan.com/scriptskewl/week9/wk9basic.php?in=clear">Clear cookies</a> on this page");
?>

<!-- A form to enter URLS, that get converted to links -->
<form method="post" action="<? $PHP_SELF ?>">
<input type="hidden" name="button" value="pushed">
<table border="0">
<tr>
<td><center>Enter some URL's to be made into links</center></td>
</tr>
<tr>
<td><strong>URL 1</strong> <A HREF="http://www.</strong><input" TARGET=_blank>http://www.</strong><input</A> type="text" size="30" name="url1" tabindex="1" value="<?php echo($_COOKIE['urlcookie1']);?>"><br>
<strong>URL 2</strong> <A HREF="http://www.</strong><input" TARGET=_blank>http://www.</strong><input</A> type="text" size="30" name="url2" tabindex="2" value="<?php echo($_COOKIE['urlcookie2']);?>"><br>
<strong>URL 3</strong> <A HREF="http://www.</strong><input" TARGET=_blank>http://www.</strong><input</A> type="text" size="30" name="url3" tabindex="3" value="<?php echo($_COOKIE['urlcookie3']);?>"><br>
</td>
<td><? print("<a href ="http://www.$url1" target=_blank>$url1</a><br><br><a href="http://www.$url2" target=_blank>$url2</a><br><br><a href="http://www.$url3" target=_blank>$url3</a>"); ?>
<td>
</tr>
<tr>
<td><center><input type="submit" value="Submit" tabindex="4"> <input type="reset" value="Reset Entries"></center></td>
</tr>
</table>
</form>
</body>
</html>


P.S. What is this 'explose' business? It's only been mentioned briefly in a past tutorial.

 

 (#787 2005-03-06 12:28:32) Post Reply

zman
Need To Set


Enrolled: Feb 2005
Posts: 15
AP: 1

This is the first one that I had a VERY hard time writing without using others code virtually ver batim... However, I never used anyone's code without knowing what it does, but with this particular assignment, the course education is beginning to fall short.

My basic assignment #9:



<?php

/* ScriptSchool.com Assignment 9 (basic)
// Description of 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.*/


$urlarray=array();
$array_url=$_COOKIE['array_url'];
$urlcookie=$_COOKIE['urlcookie'];
$action=$_REQUEST['action'];
$url=$_REQUEST['url_input'];
$addedurl = "$url";

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

if(
$action == "Reset") // check if reset button has been pressed
{
setcookie("urlcookie","",$expires); // reset the urlcookie cookie
setcookie("array_url",0,$expires); // reset the array_url cookie
}
else
{
if(
$action=='url') // INPUT FROM FORM
{
if(
$url != "")
{
$validdomain = "((^http://).+)";
if(!
eregi("$validdomain", $url))
{
$url = "http://$url";
}
$validdomain = "^http://(www\.)?.+\.(com|net|org)$";
if(!
eregi("$validdomain", $url))
{
$invalid = "yes";
}
else
{
$savedurls = explode("§", $urlcookie);
$howmanyurls = count($savedurls);
for(
$e = 0; $e < $howmanyurls; $e++)
{
if(
eregi("$addedurl", $savedurls[$e]))
{
$unique = "no";
}
else
{
if(
$urlcookie)
{
$array_url++;
setcookie("urlcookie", $urlcookie.",".$url, $expires);
setcookie("array_url", $array_url,$expires);
$added = 1;
}
else
{
setcookie("urlcookie", $url, $expires);
setcookie("array_url", 0,$expires);
$added = 1;
}
}
}
}
}
else
{
$invalid = "yes";
}
}
}
if(
$invalid == "yes")
{
print(
"<html><meta http-equiv=\"refresh\" content=\"1\">
<head><title>ScriptSchool.com Assignment 9 (basic)
</title></head><body bgcolor=\"666666\">"
);
print(
"<center><h2>You did not enter a valid URL. Entry ignored.</h2></center>");
$url_input = "";
exit;
}
if(
$unique == "no")
{
print(
"<html><meta http-equiv=\"refresh\" content=\"1\">
<head><title>ScriptSchool.com Assignment 9 (basic)
</title></head><body bgcolor=\"666666\">"
);
print(
"<center><h2>URL, ".$url_input.", already added. Entry Ignored.</h2></center>");
$url_input = "";
exit;
}
if(
$added == 1)
{
print(
"<html><meta http-equiv=\"refresh\" content=\"1\">
<head><title>ScriptSchool.com Assignment 9 (basic)
</title></head><body bgcolor=\"666666\">"
);
print(
"<center><h2>Added URL: ".$url_input."</h2></center>");
$url_input = "";
exit;
}
if(
$action == "Reset")
{
print(
"<html><meta http-equiv=\"refresh\" content=\"1\">
<head><title>ScriptSchool.com Assignment 9 (basic)
</title></head><body bgcolor=\"666666\">"
);
print(
"<center><h2>COOKIE RESET</h2></center>");
exit;
}
?>
<html><head><title>ScriptSchool.com Assignment 9 (basic)</title>
</head><body bgcolor="333333">
<center>
<table bgcolor="999999">
<tr>
<td bgcolor="666666" colspan="2"><center><b>ScriptSchool.com Assignment 9 (basic)</b></center><br />
Description of Assignment: Write a script to enter urls using a form <br />
and save the unique urls in a cookie for the current browser session,<br />
and then display the urls that are saved using the same script as <br />
active hyperlinks opening in a target window.<br /><br />
</td>
</tr>
<tr>
<td valign="top">
<table>
<tr>
<td>Add URL</td>
</tr>
<tr>
<td>
<form action= <? echo($_SERVER['PHP_SELF']); ?> method="post">
<input type="hidden" name="action" value="url" />
<input type="text" name="url_input" size="30" value="" /><br>
<input type="submit" value="Submit" /><input type="submit" name="action" value="Reset" />
</form>
</td>
</tr>
</table>
</td>
<td>
<?php
if($urlcookie)
{
$urlarray=explode(",",$urlcookie);
for(
$x=0;$x<=$array_url;$x++)
{
$displayurl=$urlarray[$x];
echo ((
$x+1)." <a href='http://".$displayurl."'>".$displayurl."</a></br>");
}
}
?>
</td>
</tr>
</table>
</center>
</body>
</html>


 

 (#790 2005-03-21 11:31:59) Post Reply

lestat
Need To Set


Enrolled: Jan 2004
Posts: 44
AP: 1

Looking good so far zman. From this point on, the tutorials DO get a bit more challenging (IMO)
Do you have a working url for us to see etc? It helps a lot.

 

 (#841 2005-06-23 10:41:56) Post Reply

vegyta2004
Need To Set


Enrolled: Apr 2005
Posts: 34
AP: 1

MY assignment:
File week9_basic.html:
<HTML>
<BODY>
<form method="POST"action="week9_basic.php">
URL1:<input type="text"name="url1"><br>
URL2:<input type="text"name="url2"> <br>
URL3:<input type="text"name="url3"> <br>
<input type="submit"value="Send URL-s"><br>
<input type="reset"value="reset data">
</BODY>
</HTML>



File week9_basic.php:
<?
if(eregi("http://www\..+\.(com|ro|net|org)",$url1))
{
if(eregi("http://www\..+\.(com|ro|net|org)",$url2))
{
if(eregi("http://www\..+\.(com|ro|net|org)",$url3))
{
$url=array($url1,$url2,$url3);
$pack=serialize($url);
setcookie("cookie_set",$pack,time()+3600);
if($cookie_set)
{
$url=unserialize(stripslashes($cookie_set));
foreach($url as $key=>$value)
echo"<a href=\"$value\">$value</a>","<br>";
} else {echo"you do not have ani info in your cookie";}
} else{echo"your url3 is invalid";}
}else{echo"your url2 is invalid";}
}else{echo"your url1 is invalid";}
?>


 

 (#919 2005-12-31 19:58:54) Post Reply

Dylan
Need To Set


Enrolled: Dec 2005
Posts: 14
AP: 1

I thought this was sort of hard too, but feeling good about getting it.

My working script is at http://www.algore.org/~admin/cookie.php

And here's the code:


<?
// 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.

if($_POST['done']) {
// erase any possible existing cookie and set new one
setcookie("link_maker");
setcookie("link_maker", $_POST['urls'], 0);

// parse the urls variable into links at the line breaks
$links = explode("\n",$_POST['urls']);

// loop to print the links
for ($x=0; $x<count($links); $x++) {
print(
"<a href=\"" . $links[$x] . "\" target=\"_blank\">" . $links[$x] . "</a>");
print(
"<br>");
}
exit;
} else {
// they haven't given URLs yet, show form
}
?>
<HTML>
<BODY>
<p>
This page will transform your URLs into hyperlinks in a new window.<br>
<font size = "-2"><i>Begin each address with http:// and start each on a new line</i></font>
</p>
<form METHOD="POST" action="<? echo($_SERVER['PHP_SELF']); ?>">
<textarea rows="6" name="urls" cols="40" WRAP>enter your URLs here</textarea><br>
<input type="hidden" name="done" value="true">
<input type="submit" value="Submit">
</BODY>
</HTML>


 

 (#977 2006-03-22 03:00:15) Post Reply

Russell
Need To Set


Enrolled: Mar 2006
Posts: 19
AP: 1

i dont know if this actually set any cookies. ill find out next lesson if i got this cookie setting thing right...



<?
if($in == "clearcookie"){
setcookie("link1");
setcookie("link2");
setcookie("link3");
print(
"Cookies cleared, <a href="$PHP_SELF">click here</a> to return to the form.");
}elseif(
$formfilled=="yes"){
if(
$url1){
setcookie("link1", $url1);}
if(
$url2){
setcookie("link2", $url2);}
if(
$url3){
setcookie("link3", $url3);}
print(
"Form filled cookies set.<br>
Here are the links you entered.<br>"
);
if(
$url1){
print(
"Link 1 Cookie Set - <a href="$url1">URL 1</a><br>");
}
if(
$url2){
print(
"Link 2 Cookie Set - <a href="$url2">URL 2</a><br>");
}
if(
$url3){
print(
"Link 3 Cookie Set - <a href="$url3">URL 3</a><br>");
}
}else{
print(
"
<h2>Setting Cookies</h2>
enter some url's below and they will be magically set into a cookie.<br>
on the next page they will magically turn into a clickable links.
<FORM METHOD="
POST" ACTION="$PHP_self">
<input type="
hidden" name="formfilled" value="yes">
<table border="
0" cellpadding="5" cellspacing="0"><tr><td align="center">
Enter URL 1
</td><td align="
center">
<input type="
text" name="url1" size="45">
</td></tr><tr><td align="
center">
Enter URL 2
</td><td align="
center">
<input type="
text" name="url2" size="45">
</td></tr><tr><td align="
center">
Enter URL 3
</td><td align="
center">
<input type="
text" name="url3" size="45">
</td></tr><tr><td align="
center">
<input type="
submit" value="Submit">
</td><td align="
center">
<input type="
reset" value="Reset">
</td></tr></table>
</form>"
);
}
?>

<br>
<a href="<? $PHP_SELF ?>?in=clearcookie">clear cookie here</a>



 

 (#978 2006-03-22 05:33:59) Post Reply

Russell
Need To Set


Enrolled: Mar 2006
Posts: 19
AP: 1

ok, that first one wasnt what i wanted - and i realized i was calling the urls out of the cookie wrong so it doesnt work anyways :/ this one is a bit more what i was aiming for. and much simpler. a couple mental notes, when you use a header redirect the variables ($formfilled, $url, etc...) disappear. that had me scratching my head for a while. another thing that stumped me was that the cookies couldnt be printed on the same page they were set. i mean i set the cookies in the script and then the next line i was trying to use if($cookiename) and that wasnt working at all. so... heres my updated code.



<?
if($formfilled=="yes"){
if(
$url1){
setcookie("link1", $url1);
}
if(
$url2){
setcookie("link2", $url2);
}
if(
$url3){
setcookie("link3", $url3);
}
header("Location: $PHP_SELF");
}
if(
$link1){
print(
"Link 1 Cookie Set - <a href=\"$link1\">URL 1</a><br>");
}
if(
$link2){
print(
"Link 2 Cookie Set - <a href=\"$link2\">URL 2</a><br>");
}
if(
$link3){
print(
"Link 3 Cookie Set - <a href=\"$link3\">URL 3</a><br>");
}
if(
$link1){
exit;
}
if(
$link2){
exit;
}
if(
$link3){
exit;
}
else{
print(
"
<h2>Setting Cookies</h2>
enter some url's below and they will be magically set into a cookie.<br>
on the next page they will magically turn into a clickable links.
<FORM METHOD=\"POST\" ACTION=\"$PHP_self\">
<input type=\"hidden\" name=\"formfilled\" value=\"yes\">
<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\"><tr><td align=\"center\">
Enter URL 1
</td><td align=\"center\">
<input type=\"text\" name=\"url1\" size=\"45\">
</td></tr><tr><td align=\"center\">
Enter URL 2
</td><td align=\"center\">
<input type=\"text\" name=\"url2\" size=\"45\">
</td></tr><tr><td align=\"center\">
Enter URL 3
</td><td align=\"center\">
<input type=\"text\" name=\"url3\" size=\"45\">
</td></tr><tr><td align=\"center\">
<input type=\"submit\" value=\"Submit\">
</td><td align=\"center\">
<input type=\"reset\" value=\"Reset\">
</td></tr></table>
</form>"
);
}
?>



 

 

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