Inserting a url into a script.

A

Anonymous

Guest
I have the following code, and would like to make it so that if $pw == $adminpass, I want it to display a url to the admin page.

if $pw does not == $adminpass, I do not want it to display that url.

How do I code that?

<?
$adminpass = "test123";
if ($pw == $adminpass)
{
<a href="go.php?url=www.google.com">google</a>
}
else
{
print("Wrong password");
}
?>
 
In the code you show below, the HTML <A href...> tag is inside the PHP script but <a href> is not php code but HTML code. The PHP processor will probably error on the tag. You need to output the HTML tag string to the HTML page, escaping the quotes that are part of the <a href> tag.

<?
$adminpass = "test123";
if ($pw == $adminpass)
{
echo "<a href=\"http://www.google.com\">Link Text</a>";"
}
else
{
echo "Wrong Password";
}

I am not sure what you are doing with the go.php?URL= code.
 
<a href> thing I put in there was just a last ditch effort to figure out what to do. I understand what you are saying about the html tag not being recognized by php, but I googled it and could not find the correct syntax.

How then would I set this up so that the URL is only displayed on a successful password entry?
 
Not sure what you are asking? What do you mean when you ask "...so that the URL is only displayed ...?" Do you want to display a link? What, exactly, should the user see if the password is correct?

The code I provided will display the URL link only if the password is correct. If you test the entered password ($pw) against the correct password ($adminpass) from a database or text file, then the code will print a link that the user can click. Are you trying to append a search string to a google URL and output the link? Or, are you wishing to redirect the user to the site with (or without) a search string?

What am I not understanding about your question.
 
Sorry, I misunderstood your post. I tried the code you provided, That was the answer I was looking for.
 
Back
Top