4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 http and php
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
domuk
WebHelper
WebHelper


Joined: 15 Jan 2004
Posts: 91

PostPosted: Sun May 23, 2004 11:37 am (13 years, 5 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by domukSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sun May 23, 2004 1:53 pm (13 years, 5 months ago) Reply with QuoteBack to Top

Shouldn't this
Code:
$combind = $a . $grid_ref . $b;
be changed to this?
Code:
$combind = $a . $ref . $b;

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
domuk
WebHelper
WebHelper


Joined: 15 Jan 2004
Posts: 91

PostPosted: Mon May 24, 2004 5:12 pm (13 years, 4 months ago) Reply with QuoteBack to Top

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?
OfflineView User's ProfileFind all posts by domukSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Mon May 24, 2004 6:07 pm (13 years, 4 months ago) Reply with QuoteBack to Top

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).

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
domuk
WebHelper
WebHelper


Joined: 15 Jan 2004
Posts: 91

PostPosted: Mon May 24, 2004 7:15 pm (13 years, 4 months ago) Reply with QuoteBack to Top

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 Confused

Do you understand my question?
OfflineView User's ProfileFind all posts by domukSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Mon May 24, 2004 7:21 pm (13 years, 4 months ago) Reply with QuoteBack to Top

You do realise that once you have written the cookie, you can output HTML, don't you?

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
domuk
WebHelper
WebHelper


Joined: 15 Jan 2004
Posts: 91

PostPosted: Tue May 25, 2004 7:59 am (13 years, 4 months ago) Reply with QuoteBack to Top

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?
OfflineView User's ProfileFind all posts by domukSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Tue May 25, 2004 4:18 pm (13 years, 4 months ago) Reply with QuoteBack to Top

Use one page for the form (page1.php Smile), which submits to another script (page2.php Smile, which now sets the cookie). Or is that not what you mean?

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
domuk
WebHelper
WebHelper


Joined: 15 Jan 2004
Posts: 91

PostPosted: Tue May 25, 2004 5:11 pm (13 years, 4 months ago) Reply with QuoteBack to Top

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...
OfflineView User's ProfileFind all posts by domukSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Tue May 25, 2004 5:21 pm (13 years, 4 months ago) Reply with QuoteBack to Top

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']; ?>" />

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
domuk
WebHelper
WebHelper


Joined: 15 Jan 2004
Posts: 91

PostPosted: Tue May 25, 2004 5:56 pm (13 years, 4 months ago) Reply with QuoteBack to Top

Quote:
If I understood correctly, you want to know how to pass data between pages?


Yes Razz 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
OfflineView User's ProfileFind all posts by domukSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Tue May 25, 2004 6:04 pm (13 years, 4 months ago) Reply with QuoteBack to Top

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'].

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
domuk
WebHelper
WebHelper


Joined: 15 Jan 2004
Posts: 91

PostPosted: Tue May 25, 2004 6:25 pm (13 years, 4 months ago) Reply with QuoteBack to Top

Thank's I shall give that a go.... Wink
OfflineView User's ProfileFind all posts by domukSend Personal Message
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.061529 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme