Jump to content

urlencode()


woolyg

Recommended Posts

Hi all,

 

I'm having difficulties with urlencode() - can anyone help? What I'm trying to do is use an HTML refresh on one page (log_me_in.php) to open another (main.php?badlogin=true), but it just won't work for me.

 

Here is the code from log_me_in.php:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<?php 
$str = "true";
	$string = urlencode($str); ?>
<meta http-equiv="refresh" content="0;URL=main.php?badlogin=<?php echo $string; ?>" />
<title>Bad login - Redirecting...</title>
</head>
<body>
</body>
</html>

 

 

..and here is the code for main.php:

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Main</title>
</head>

<body>
<?php echo $_GET['badlogin']; ?>
</body>
</html>

 

 

On main.php, $_GET['badlogin'] is not displaying. I understand (from reading prior issues like this) that with standard characters it shouldn't be necessary to use urlencode() in the first place, but I've been told by my web host that it is necessary to use.

 

Can anyone help? All input appreciated.

 

Woolyg.

 

 

Link to comment
https://forums.phpfreaks.com/topic/86040-urlencode/
Share on other sites

Why cant you just send a header instead i.e - before any html have something like

if  ($login == "bad") {
    header("location:main.php?login=bad");
   exit;
}

 

urlencode will only affect strings with non alpha-numeric characters in them.

 

Btw, meta-refresh is deprecated.

meta_refresh on wikipedia

Link to comment
https://forums.phpfreaks.com/topic/86040-urlencode/#findComment-439384
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.