Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by duncanb7
at 2024-05-07 02:29:22
Point:500 Replies:8 POST_ID:828551USER_ID:11059
Topic:
PHP Scripting Language;Hypertext Markup Language (HTML);JavaScript
From the following set cookies php script from google seach example, I have quetion
Question-1
why the cookies.php as follow will re-run again after form is submitted ?
I just make echo statment on the top of the code to test
the script is re-run again.
In first run, when user type http://www.mywebsite.com/cookies.php, it will
echo out on IE and display Null at $user variable
echo "user variable is changing to =
And then I submit the form after typing username and click radio button
it will echo out in IE and display
echo "user variable is changing to = myusername
Whether when click submit button with method="POST", it will let the php
script re-run again ?
Question-2
Why it uses $user = $_POST['user'] ? And not $_SESSION['user']
When we will use $_SESSION and $_POST ?
Please advise
Duncan
The following code is in file of cookies.php
Question-1
why the cookies.php as follow will re-run again after form is submitted ?
I just make echo statment on the top of the code to test
the script is re-run again.
In first run, when user type http://www.mywebsite.com/cookies.php, it will
echo out on IE and display Null at $user variable
echo "user variable is changing to =
And then I submit the form after typing username and click radio button
it will echo out in IE and display
echo "user variable is changing to = myusername
Whether when click submit button with method="POST", it will let the php
script re-run again ?
Question-2
Why it uses $user = $_POST['user'] ? And not $_SESSION['user']
When we will use $_SESSION and $_POST ?
Please advise
Duncan
The following code is in file of cookies.php
<?php $user = $_POST['user']; $color = $_POST['color']; $self = $_SERVER['PHP_SELF'];echo "user variable is changing to =".$user; if( ( $user != null ) and ( $color != null ) ) { setcookie( "firstname", $user , time() + 86400 ); // 24 hours setcookie( "fontcolor", $color, time() + 86400 ); //header( "Location:cookies2.php" ); exit(); }?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><html><head> <meta http-equiv="content-type" content="text/html;charset=ISO-8859-1"> <title>Stuff by tedd</title></head><body> <h1>tedd's cookie stuff</h1> <hr> <form action ="<?php echo( $self ); ?>" method = "post"> Please enter your first name: <input type = "text" name = "user"><br><br> Please choose your favorite font color:<br> <input type = "radio" name = "color" value = "Red">Red <input type = "radio" name = "color" value = "Green">Green <input type = "radio" name = "color" value = "Blue">Blue <br><br> <input type = "submit" value = "submit"> </form> <br/> <hr></body></html></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:
Expert: Ray Paseur replied at 2024-05-13 10:38:31
Yes, the book is available in both bound paper and PDF. A newer link exists (there is now a 5th edition) and the link above redirects to the newest version.
http://www.sitepoint.com/books/phpmysql5/
http://www.sitepoint.com/books/phpmysql5/
Author: duncanb7 replied at 2024-05-13 10:25:42
Is the book in soft copy so that I can buy it from internet and outside of US ?<br />Anyway I will check it by myself to the purchase link<br /><br />THanks<br /><br />Duncan
Expert: ModCorlEEone replied at 2024-05-10 06:33:02
duncanb7,
I have reopened your question, either because you asked for it directly, or because someone else suggested it and it appears you agreed.
Please be sure to either re-close your question with your desired disposition, or continue the dialog with the Experts as appropriate.
ModCorlEEone
Community Support Moderator
I have reopened your question, either because you asked for it directly, or because someone else suggested it and it appears you agreed.
Please be sure to either re-close your question with your desired disposition, or continue the dialog with the Experts as appropriate.
ModCorlEEone
Community Support Moderator
Accepted Solution
Expert: Ray Paseur replied at 2024-05-08 06:37:49
225 points EXCELLENT
Wow, I tried to explain the issues, and for my effort I got the worst possible grade you can give to someone at EE? The question requires a narrative answer. Please take a look at the grading guidelines here.
http://www.experts-exchange.com/help/viewHelpPage.jsp?helpPageID=26
I'd like to continue to help, but I think you would be better off to get the SitePoint book and start there so that you can get some grip on the basics of the language.
Let's try to deconstruct this question...
Will the script re-run? That is anybody's guess. The script tests to see if two data elements are not NULL (line 7). If both are not NULL, the script will try setcookie() and then exit. So depending on the data that the client entered, the script might re-run or might not re-run. But in any case, the call to setcookie() will fail for the reasons outlined above.
Is this making sense to you?
http://www.experts-exchange.com/help/viewHelpPage.jsp?helpPageID=26
I'd like to continue to help, but I think you would be better off to get the SitePoint book and start there so that you can get some grip on the basics of the language.
Let's try to deconstruct this question...
because it is method="post in form and the script will re-run by submitting the form, RIght ?
A form is an HTML construct that enables a client web page to make an HTTP request to a server. The most common methods of request are GET and POST. GET is used to "get" information when no changes are needed on the data model of the server. POST is used to send information to the server when that information changes the data model of the server or the state of the client. Examples of this include logging in, purchasing products, signing up for events, etc. A POST request would be appropriate in the script you posted here because it attempts to set a cookie, and cookies are used to change the state of the client.Will the script re-run? That is anybody's guess. The script tests to see if two data elements are not NULL (line 7). If both are not NULL, the script will try setcookie() and then exit. So depending on the data that the client entered, the script might re-run or might not re-run. But in any case, the call to setcookie() will fail for the reasons outlined above.
Is this making sense to you?
Author: duncanb7 replied at 2024-05-07 02:56:41
because it is method="post in form and the script will re-run by submitting the form, RIght ?
Assisted Solution
Expert: Ray Paseur replied at 2024-05-07 02:51:41
225 points EXCELLENT
Please, please give yourself some opportunity to learn PHP in a structured way, such as buying this book and working through the text and examples. From this and your other questions it seems like you're floundering about and not really getting a good understanding of how the language works. You can learn PHP, but not by reading other people's code without any understanding of the thought processes. The SitePoint book will tell you what the author was thinking and how the code implements the ideas.
http://www.sitepoint.com/books/phpmysql4/
In the script above an echo precedes setcookie(). Cookies are part of the HTTP headers and all headers must come first, and be complete, before any browser output. Echo creates browser output, so the setcookie() function fails.
The $_POST array is a superglobal variable, present in every scope and namespace. It is empty if a POST-method request has not been made. The script should test to see if $_POST is empty() before trying to use information from an empty variable.
The $_SESSION array is also a superglobal variable. It is (unfortunately) usable whether or not session_start() has completed successfully. You use $_POST to collect external data from a POST-method request. You use $_SESSION to store data that is originated in your script, when you want this data to be available to other pages of your web site.
You will find that your programming life is a lot easier if you add error_reporting(E_ALL) to the top of your scripts. PHP makes a lot of assumptions and does so silently. A raised error reporting level will help you find some of the silent errors (such as relying on undefined indexes in the $_POST array).
http://www.sitepoint.com/books/phpmysql4/
In the script above an echo precedes setcookie(). Cookies are part of the HTTP headers and all headers must come first, and be complete, before any browser output. Echo creates browser output, so the setcookie() function fails.
The $_POST array is a superglobal variable, present in every scope and namespace. It is empty if a POST-method request has not been made. The script should test to see if $_POST is empty() before trying to use information from an empty variable.
The $_SESSION array is also a superglobal variable. It is (unfortunately) usable whether or not session_start() has completed successfully. You use $_POST to collect external data from a POST-method request. You use $_SESSION to store data that is originated in your script, when you want this data to be available to other pages of your web site.
You will find that your programming life is a lot easier if you add error_reporting(E_ALL) to the top of your scripts. PHP makes a lot of assumptions and does so silently. A raised error reporting level will help you find some of the silent errors (such as relying on undefined indexes in the $_POST array).
Author: duncanb7 replied at 2024-05-07 02:33:24
Could you answer all QUESTION-1 and -2 for all "?"
Assisted Solution
Expert: IanTh replied at 2024-05-07 02:31:36
50 points EXCELLENT
$-post is the way data is got from the form