-2

Possible Duplicate:
Creating javscript function to destroy php session

Hi I am trying to create a php variable that will display itself as a popup. Here is the code I have...

    <?php 
 // this starts the session 
 session_start(); 
 $var = "";

 // echo variable from the session, we set this on our other page 
 if ($_SESSION['color'] == "") {
        $var = "<a href='JavaScript:newPopup('http://www.yourfantasyfootballreality.com/signin.php');' class='two'>Sign In</a>";
    } else {
    echo "Hello, ";
    }
 echo $var;
 ?> 

I can't seem to arrange the semicolons and quotes correctly. Can someone please show me how this is done.

0

2 Answers 2

3

You can escape the quote character you are using to delimit your string within the string with the escape character (\)...

$var = "<a href=\"JavaScript:newPopup('http://www.yourfantasyfootballreality.com/signin.php');\" class=\"two\">Sign In</a>";

Alternatively, you can mix quotes, i.e. use single quotes to delimit your string and double quotes for quotes around your attributes or vice versa.

You could also use heredoc or nowdoc.

Sign up to request clarification or add additional context in comments.

Comments

1

In "<a href='JavaScript:newPopup('http://www.yourfantasyfootballreality.com/signin.php');' class='two'>Sign In</a>"; the 2nd ' closes the href tag. You need to escape it, so you would do something like:

$var = "<a href='JavaScript:newPopup(\"http://www.yourfantasyfootballreality.com/signin.php\");' class='two'>Sign In</a>";

So that when it actually outputs you get <a href='JavaScript:newPopup("http://www.yourfantasyfootballreality.com/signin.php");' class='two'>Sign In</a>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.