473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

GET POST or which methode should you use ?

20
Good time everyone here
When I created an account on this site I got this url:
http://www.thescripts.com/forum/regi...hp?do=register
So now I have a question about ?do=register and what does this mean ?
Suppose you have a web page named main.php with some links to different pages with same layout (one table) but different contents depending on what the visitor clicks.

For example:
Link 1 leads you to page with content Hello link 1
Link 2 ==> Hello link 2
...

Do you have to create 2 pages for this script?

Let us take a look at the source code of this site:
Expand|Select|Wrap|Line Numbers
  1. <form action="http://www.thescripts.com/forum/register.php" > .. </form>
Another example but not for paging, suppose you wanne make a little quiz system like this following one:
index.php
[PHP]<html><head><title>..</title></head>
<body>
<form action ="process.php" method="post">
What is democracy? <br />
<input type="text" id="answer" /><br />
<input type="submi" id="Control the answer" />
</form>
<?php
$result = flase;
if ($result) {
echo("Good answer");
else
echo("Try again!");
}
?>
</body>
</html>
[/PHP]
process.php
[PHP]<?php
$answer = $_POST['answer'];
$result = flase;

if ($answer = 'democracy means protecting the capitalists')
$result = true;
else
$result = flase;

Redirect header("Location: index.php");
?> [/PHP]

So how do you link the $result variable with the index.php page or how do you pass this to other pages ?

Let's make the knowledge/experience open source and share it with each other ;)
Jan 27 '08 #1
10 2056
stepterr
157 100+
Good time everyone here
When I created an account on this site I got this url:
http://www.thescripts.com/forum/regi...hp?do=register
So now I have a question about ?do=register and what does this mean ?
Suppose you have a web page named main.php with some links to different pages with same layout (one table) but different contents depending on what the visitor clicks.

For example:
Link 1 leads you to page with content Hello link 1
Link 2 ==> Hello link 2
...

Do you have to create 2 pages for this script?

Let us take a look at the source code of this site:
Expand|Select|Wrap|Line Numbers
  1. <form action="http://www.thescripts.com/forum/register.php" > .. </form>
Another example but not for paging, suppose you wanne make a little quiz system like this following one:
index.php
[PHP]<html><head><title>..</title></head>
<body>
<form action ="process.php" method="post">
What is democracy? <br />
<input type="text" id="answer" /><br />
<input type="submi" id="Control the answer" />
</form>
<?php
$result = flase;
if ($result) {
echo("Good answer");
else
echo("Try again!");
}
?>
</body>
</html>
[/PHP]
process.php
[PHP]<?php
$answer = $_POST['answer'];
$result = flase;

if ($answer = 'democracy means protecting the capitalists')
$result = true;
else
$result = flase;

Redirect header("Location: index.php");
?> [/PHP]

So how do you link the $result variable with the index.php page or how do you pass this to other pages ?

Let's make the knowledge/experience open source and share it with each other ;)
For the example that you have given, you would probably be better off using a session variable if you want to have the value of $result shared among several pages.
Jan 27 '08 #2
Markus
6,050 Expert 4TB
$_GET is normally used in Content Management Systems, i.e. you use $_GET to retrieve which oage should be displayed, then you query your database; which will have a series of stories in it - lets say, then that story will be displayed on the initial page. This method is known as 'dynamic'.

$_POST, however, is the basis of forms - unlike $_GET which is primarily used on hyperlinks. $_POST has a greater amount of space you can use, compared to $_GET which is limited to a certain amount because the url address bar will only allow so many characters.

$_POST is also invisible to the world! Therefore, you should use this when passing private information, i.e, passwords, login data, etc.

Neither one is better to use, they're made for different purposes.
Jan 27 '08 #3
bchaib
20
...

Neither one is better to use, they're made for different purposes.
:-) absolutly, I think I'm going to try sessions ..

Thanks
Jan 27 '08 #4
bchaib
20
For the example that you have given, you would probably be better off using a session variable if you want to have the value of $result shared among several pages.
Thanks, I'm going to do that .. but is that the only solution?
You have also things like n-tier application, there you should split your application
into different layers
HTML with {example} PHP references
PHP database
PHP connection
PHP variables
...

Just like we do using CSS, Javascript and XHTML.

I'm looking for a good tutorial using this way ..

Thank you
Jan 27 '08 #5
Session variables aren't the only solution to the your problem. It really comes down to how you want to handle passing of data in your app. You can $_POST back to the same script using $_server['php_self'] via form, or you can send $_GET variables back to the same script in an href.

You have to be careful of variable scope if you do this. And you can add some re-usability by filtering the page content using something like:
Expand|Select|Wrap|Line Numbers
  1. if (isset($_GET['somevar'] ) {
  2.        if ($_GET['somevar'] == value1)
  3.              {
  4.                echo "something";
  5.              }else{
  6.                echo "something else";
  7.              }
  8.         }
  9.  
to create the window.

Another method would be to use $_COOKIE to set a cookie using js then read it via embedded function on your page loads that need whatever info that you are needing to be persistent.

Regards,
Jenkins
Jan 27 '08 #6
stepterr
157 100+
Thanks, I'm going to do that .. but is that the only solution?
You have also things like n-tier application, there you should split your application
into different layers
HTML with {example} PHP references
PHP database
PHP connection
PHP variables
...

Just like we do using CSS, Javascript and XHTML.

I'm looking for a good tutorial using this way ..

Thank you
Like Jenkins says, sessions are not the only solution, cookies are another good option. But if you were to use the $_GET you'd have to link to a page and include the value in the url each time and if you were to use a $_POST then you are would need to have the values in your form and submit it to the other page and then grab it using the $_POST each time. I just find it easier that if I'm going to be using the same value across multiple pages of my site that storing it in a session variable has worked out the best. Now if you are just going to use a value between two pages then the $_GET and the $_POST will be all you need, but it doesn't sound like that was what you were looking for.
Jan 27 '08 #7
bchaib
20
But I get some errors :(

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\www\www\db\procces.php:1) in C:\www\www\db\procces.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at C:\www\www\db\procces.php:1) in C:\www\www\db\procces.php on line 4
Jan 28 '08 #8
stepterr
157 100+
Where have you placed the headers on your page?
Jan 28 '08 #9
bchaib
20
Where have you placed the headers on your page?
after the php control:
.................................................. ......
[HTML]<?php
session_start();
if (!IsSet($_SESSION['login'])) {
header("Location: index.php");
exit(0);
}

?>

<!DOCTYPE html PUBLIC "-//W3C//Dtd XHTML 1.0 transitional//EN" "http://www.w3.org/tr/xhtml1/Dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Title here : some text</title>[/HTML]

BUT
I have this page saved in a sub directory of data directory.
I have the html login control and session variable in another directory!
Jan 28 '08 #10
stepterr
157 100+
after the php control:
.................................................. ......
[HTML]<?php
session_start();
if (!IsSet($_SESSION['login'])) {
header("Location: index.php");
exit(0);
}

?>
Take a look at this site about the session_start() function, particularly in the comments below concerning session_start() and header(). http://nl2.php.net/manual/en/function.session-start.php
Then you can also look at this link for the header() function. http://nl2.php.net/manual/en/function.session-start.php
Both are good to look at to see how you may need to get around this issue.
Jan 30 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Jan Roland Eriksson | last post by:
I have worked some more on this suggested new mFAQ version trying to get all user input to blend into the text. Another review by the NG would be welcome. ===== Archive-name:...
5
by: Jan Roland Eriksson | last post by:
Some more fine tuning and inclusion of last suggested text from regulars has been done to this test post #4 of the mFAQ. As usual, rip it up anywhere you feel that it's appropriate to do so. ...
12
by: Assaf | last post by:
Hi all, My client is using an online service provider that processes survey responses. After a user fills survey.aspx and presses the OK button, 2 things need to happen: 1. the data has to...
5
by: Vishal | last post by:
Hello, I already asked this question in the ASP.NET forums, but no help came. So I am hoping that somebody can help me out. This is really very URGENT me. For my e-commerce application, I...
2
by: LD | last post by:
Hi, I am trying to upload a zip file and other form data elements to a server and get a response. The server keeps responding with Malformed Multipart Post. Can anyone see what might be wrong...
24
by: moriman | last post by:
Hi, The script below *used* to work. I have only just set up a server, PHP etc again on my Win98 system and now it doesn't? On first loading this page, you would have $p = and the button...
0
by: andreas | last post by:
Bill, what are you doing? I see the methode count in vb.net and in vb.net express but not in vb.net 2003 int = treeview.nodes.count Int = treeview1.nodes(i).nodes.count
5
by: Thomas Kowalski | last post by:
Hi everyone, recently I have trouble to pass an array (unsigned char color) to a methode by reference and collect the return value by reference. I wanted something like: unsigned char&...
7
by: php_mysql_beginer911 | last post by:
Hi .. hope someone will help i am trying to figure it out why i cannot post string "union select" every time i try to post data which content union and select .. the page doesn't get posted and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.