Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookie query

Status
Not open for further replies.

disturbedone

Vendor
Sep 28, 2006
781
0
0
AU
Hi,relative PHP newbie here, be nice :)

Scenario: Apache web server (IP PBX) eg 192.168.1.1 hosting page that allows user to log in to and control their phone. User page allows a panel to display an HTML/PHP page, which is hosted on another Apache server on eg 192.168.1.50, that I've written that searches and LDAP directory which works perfectly. When search displays results one field if their phone number. A URL is available to create a call eg (where num2 is the value obtained from the db).

Issue: Somehow I need to populate the num1 parameter in the URL. When a user logs on to the page they enter their xtn and pword which is stored as a cookie.

Question: Is it possible, somehow, to get my page to query the cookie that was supplied by the other web server? Querying the cookie should supply the value of the xtn they are logged in with and I can then put that in my URL. The issue I'm not sure of is that the cookie is supplied by one server and I want to query it from another.

Clear as mud? Any suggestions welcome.
Thx
 
in a word, no. cookies are sent by the browser and the web server has no say in what it receives.

so i would think again about storing that kind of data in a cookie and instead store it in a session variable and use a cookie to help identify the user (and instantiate the session) on each server. you need do nothing more than this

Code:
session_start();
$_SESSION['num1'] = (empty($_SESSION['num1'])) ? getNum1FromSomewhere(); $_SESSION['num1'];

where getNum1FromSomewhere() is a function that populates the num1 variable for you. i would craft this function using cURL or file_get_contents() to point at the remote server and grab the response. it's only a few lines of code and means that you don't need to have user interaction on the foreign web server.



 
Hi, I'm not sure if I explained things clearly or if I have things mixed up.

To my knowledge, cookies are sent by the webserver to the client ie when a client logs in as user/pword the server will send a cookie to the client which will be stored on your PC, when the client browses to that page again it sends the cookie back to the server so it knows who it is. Correct?

The issue is that I have 2 servers - one on 192.168.1.1 (which I cannot get access to or modify any code on) which sends a cookie to the client saying you've logged on to that page as '400'. The server that I'm hosting another page on, 192.168.1.50, needs to (if poss) query the cookie which is stored locally on the PC and take the data ie '400' and use it as a variable.

Upon Googling I found bits about the PHP code $_COOKIE which can be used to read a cookie eg

<?php
// Print a cookie
echo $_COOKIE["user"];
?>

displays the cookie named 'user'.

However when I hosted that simple script on my server it displays nothing, even though if I view cookies in Firefox there are plenty. So I'm not sure what I'm missing.

Hopefully that explains a little more clearly what I'm trying to do.

Thx
 
nothing has changed. cookies work on a per domain basis. your browser is correctly treating 192.168.1.1 as a different domain to 192.168.1.50.

if you want to change the behaviour and do not want to use sessions then set up dns so that both machines are inside the same domain and then specify your cookie to be at the domain level (rather than the fully qualified domain level).

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top