Inserting a url into a script.

General discussions related to php

Moderators: macek, egami, gesf

ckwall

Inserting a url into a script.

Postby ckwall » Fri Jan 24, 2003 1:01 pm

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");
}
?>

greg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Nov 13, 2002 6:56 am

Outputting a URL link with a PHP script

Postby greg » Sat Jan 25, 2003 12:01 pm

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.

ckwall

Postby ckwall » Mon Jan 27, 2003 5:11 pm

<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?

greg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Nov 13, 2002 6:56 am

???

Postby greg » Mon Jan 27, 2003 6:21 pm

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.

ckwall

Postby ckwall » Mon Jan 27, 2003 8:55 pm

Sorry, I misunderstood your post. I tried the code you provided, That was the answer I was looking for.


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 2 guests