Author |
Message |
domuk
WebHelper
Joined: 15 Jan 2004
Posts: 91
|
Posted:
Sun May 23, 2004 11:37 am (19 years, 11 months ago) |
|
I would like to find out how to generate and call this link “http://example.cgi?client=public&&quicksearch=test&&scale=25000” using PHP and to specify “test” from the user inputting the word “test” in a PHP generated textbox. This is what I have got so far.
ref_1.php
Code: | <?php
$ref = 'test'; //
setcookie("ref_cookie", $ref);
echo '<a href="_____/ref.php">link</a>';
?> |
ref.php
Code: | <?php
$ref = $_COOKIE["ref_cookie"];
$a = 'location: http://www.example.cgi?client=public&&quicksearch=';
$b = '&&scale=25000';
$combind = $a . $ref . $b;
header ($combind); // no print or echo statments before this line
?> |
I call ref_1.php and click the link which calls ref.php It’s the text box, the order of setting the cookie and the header that I am having problems with. Can it be done just using PHP or should I look at javascript?
thanks,
Dom |
Last edited by domuk on Mon May 24, 2004 5:14 pm, edited 1 time in total |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sun May 23, 2004 1:53 pm (19 years, 11 months ago) |
|
Shouldn't this Code: | $combind = $a . $grid_ref . $b; | be changed to this? Code: | $combind = $a . $ref . $b; |
|
________________________________
|
|
|
|
domuk
WebHelper
Joined: 15 Jan 2004
Posts: 91
|
Posted:
Mon May 24, 2004 5:12 pm (19 years, 11 months ago) |
|
sorry, you are correct. I use to call it grid_ref and I must have mistyped it in my post.
I can get it to pass 'test' to the ref.php file (via a cookie) and then send it to the cgi script (which works), but I can not manage to write the cookie after the user has been presented with the form (html form generated with php).
In essence the problem is that I have to send the cookie and the
headder($combind); before any html is sent to the browser.
Any Ideas Daniel? |
|
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Mon May 24, 2004 6:07 pm (19 years, 11 months ago) |
|
Sorry, I don't understand your question; specifically this part: Quote: | but I can not manage to write the cookie after the user has been presented with the form (html form generated with php). |
|
________________________________
|
|
|
|
domuk
WebHelper
Joined: 15 Jan 2004
Posts: 91
|
Posted:
Mon May 24, 2004 7:15 pm (19 years, 11 months ago) |
|
As I understand it you have to write the cookie before any HTML is sent to the browser otherwise you get an error eg:
Quote: | "warning cannot add header information - headers already sent by ........etc" |
therefore when the form has been presented to the user I can not set the cookie using PHP.
If I wanted to use PHP I think I would need to have a separate php file with no html output to the browser to write the cookie, is this the case?
I think I may need to use Javascript, but I was wondering if it could be done with PHP.
Sorry for the drawn out explanation
Do you understand my question? |
|
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Mon May 24, 2004 7:21 pm (19 years, 11 months ago) |
|
You do realise that once you have written the cookie, you can output HTML, don't you? |
________________________________
|
|
|
|
domuk
WebHelper
Joined: 15 Jan 2004
Posts: 91
|
Posted:
Tue May 25, 2004 7:59 am (19 years, 11 months ago) |
|
Yes.
But you can not output HTML, weight for the user to enter information into a text box and then write the cookie with the data from the text box. Can you?
I want to write the cookie with the data from the text box not write the cookie and then output the html..
Sorry if I am not making my self clear, do you understand? |
|
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Tue May 25, 2004 4:18 pm (19 years, 11 months ago) |
|
Use one page for the form (page1.php ), which submits to another script (page2.php , which now sets the cookie). Or is that not what you mean? |
________________________________
|
|
|
|
domuk
WebHelper
Joined: 15 Jan 2004
Posts: 91
|
Posted:
Tue May 25, 2004 5:11 pm (19 years, 11 months ago) |
|
Sorry Daniel,
this is what i mean:
1) construct the form (with page1.php)
2) read 4 text boxes and one combo box ("xx"/ "11"/ "22"/ "33"/"44")(with page1.php)
3) join them together ("xx11223344")(with page1.php)
4) write the string to a cookie(with page1.php)
5) read the cookie with (page2.php)
6) construct the header (with page2.php)
7) call example.cgi (with page2.php)
Page2.php
Code: | $ref = $_COOKIE["ref_cookie"];
$a = 'location: http://www.example.cgi?client=public&&quicksearch=';
$b = '&&scale=25000';
$combind = $a . $ref . $b;
header ($combind); // no print or echo statements before this line |
I am not sure how to do page 1. I would like to get to stage 7 before I submit page1.php. I am not sure if this is possible in two php documents
I think I need more, but I am unsure how to split the operations.
I think I need so see some examples of data being passed from server to browser and back again in one php document or I need to see a dynamically staged construction of a html form with a php document.
Do you understand what I am asking?
I am sorry for confusing you, I am trying to get my head round php without knowing fully what it can do.
Thanks for your help,
I really appreciate it,
Dom... |
|
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Tue May 25, 2004 5:21 pm (19 years, 11 months ago) |
|
If I understood correctly, you want to know how to pass data between pages?
If so, you should put the values of the previous page into hidden <input> fields to keep their values when submitting:
Code: | <input type="hidden" name="fieldname" value="<?php echo $_GET['fieldname']; ?>" /> |
|
________________________________
|
|
|
|
domuk
WebHelper
Joined: 15 Jan 2004
Posts: 91
|
Posted:
Tue May 25, 2004 5:56 pm (19 years, 11 months ago) |
|
Quote: | If I understood correctly, you want to know how to pass data between pages? |
Yes I have been trying to do it with cookies.
Could you please point me in the direction of a tutorial on this issue?
Quote: | If so, you should put the values of the previous page into hidden <input> fields to keep their values when submitting:
|
I am not totally sure what you mean by this with respect to the two php pages, could you please explain.
Thanks,
Dom |
|
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Tue May 25, 2004 6:04 pm (19 years, 11 months ago) |
|
Actually, now that I realise what you're wanting to do, I don't think cookies are necessary. What's wrong with passing data with POST form fields?
If you submit a form via the POST method with a field named 'fieldname', you can access its value with the variable name $_POST['fieldname']. |
________________________________
|
|
|
|
domuk
WebHelper
Joined: 15 Jan 2004
Posts: 91
|
Posted:
Tue May 25, 2004 6:25 pm (19 years, 11 months ago) |
|
Thank's I shall give that a go.... |
|
|
|
|
|