create session from javascript value

ellandrd
ellandrd used Ask the Experts™
on
how can i create a PHP session from a javascript value?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007
Commented:
See http://de.php.net/manual/en/faq.html.php#faq.html.javascript-variable

<?php
if (isset($_GET['width']) AND isset($_GET['height'])) {
  // output the geometry variables
  echo "Screen width is: ". $_GET['width'] ."<br />\n";
  echo "Screen height is: ". $_GET['height'] ."<br />\n";
} else {
  // pass the geometry variables
  // (preserve the original query string
  //   -- post variables will need to handled differently)

  echo "<script language='javascript'>\n";
  echo "  location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}"
            . "&width=\" + screen.width + \"&height=\" + screen.height;\n";
  echo "</script>\n";
  exit();
}
?>

Author

Commented:
isnt this creating a javascript value based on a PHP value?  i want the opposite.
Top Expert 2007

Commented:
Maybe you can explain a little more in detail what you want. The given example sends two java-script variable to php.
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Author

Commented:
ok i cant find anything to help me in the documentation.

this is what im trying to do:

i have a parent window with a button.  when clicked i open a popup window.  i want to get the URL of the parent window.  i then want to use this parent window url to decide which page i return to when i close the child window.

so far i can get the url of the parent window and display it using a alert().  

Author

Commented:
maybe this will help too.  here my my code to close the popuo window and return to parent:

$html .= '<td><a href="javascript:void(0);" title="Use this Template" onclick="javascript:window.opener.location=window.parent.opener.location+"?cat_id="'.trim($rows['CatID']).'\';self.close();return true;">Use</a></td>'."\n";
                        

Author

Commented:
ok i think that was a bad example.  

lets try again. my popup window contains a list of hrefs.  when one of these links are clicked i want to set the location of parent window and also pass back a value and close the popup.

$url = 'javascript:window.opener.location=window.opener.location?cat_id='.trim($rows['CatID']).';self.close();return true;';
                                          
$html .= '<a href="javascript:void(0);" onclick="'.$url.'">Use</a>'."\n";

But it isnt working - im getting  a syntax error.
                        

Author

Commented:
thanks for the help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial