Problem with short script

Hi there,
I get an output I can’t explain.

<?php
if (!isset($_SESSION)) {
   session_start();
}
include "mysqlopen.php";
    $uname="";
    $pwd="";
   if(isset($_REQUEST['uname']))
    {
        $uname = $_REQUEST['uname'];
    } 
    if(isset($_REQUEST['pwd']))
    {
        $pwd = $_REQUEST['pwd'];
    }
if ($uname="" or $pwd=""){
      return;
 }
echo "so far...";
?>

gives me the output:
?> so far…
Since it is pure PHP, I can’t see where ?> is coming from.
any help welcome

Do you have a spurious ?> in mysqlopen.php by any chance?

What is the return statement supposed to do?

Blush.
Right. Think further than one script when include.
Thank you very much.
The return goes back to the login page. I hope. Just read the manual.I have not a strategy for false inputs yet.
In fact I want to keep the previous inputs of the user; it’s irritating being forced to write all over again.

I don’t think return is going to work there - it’s not a function.

So long as you’ve not output anything to the browser, you should be able to use header to redirect back to the login page.

I wrote a function for that now, thanks. Wanted to avoid lol
In the PHP manual it says: Returns to the calling script. It doesn’t.

Try adding this declaration and two debug settings at the start of your PHP script. Remove when online.

<?php
declare(strict_types=1); // applies to this file only
error_reporting(-1); // applies to this and included files
ini_set('display_errors','1'); // applies to this and included files

Actually you can return from a script as well. You can even return a value to the script that includes it:

a.php:

$a = require 'b.php';

echo $a;

b.php:

return 'Hello world';

When you run a.php, it will echo Hello world.

Not saying it’s a good idea, just saying it’s possible :wink:

2 Likes