Jump to content

Recommended Posts

Hi, here's my problem..

 

I have a php generated page with a hyperlink which opens in a new window

 

echo "<tr><td><a onclick=\"window.open('http://www.***.com/page/options.php?user_id=$user_id&session_id=$session_id','options','width=590,height=200,toolbar=no,scrollbars=yes,resizable=yes,statusbar=no,directories=no,menubar=no,location=no');return false;\" href=\"\">$user_id</a></td></tr>";

 

The problem occurrs at options.php?user_id=$user_id

 

The resulting hyperlink on the generated page adds a space to the user id after the "="

 

So when options.php loads.. it results in the user's id having an extra %20 at the beginning of their name

 

Example..

 

The first page links to this.. http://www.***.com/page/options.php?user_id= Eejut&session_id=12345

 

When options.php loads it prints..

 

"This is %20Eejut's Options Page"

 

I've tried using trim($user_id) before printing the hyperlink to the main page (that calls options.php) and the space still occurrs in the hyperlink

 

Anyone know what's going wrong?? thanks in advance

 

 

Either your code that is setting $user_id is adding the space or you actually have a space in your data.

 

Edit: In fact, I'm going guess you have some code that looks like this - $user_id = " {$row['user_id']}";

Here's the code that uses

 

//get list of active members

$activemembers = file('activemembers.txt');

if (!$activemembers) {echo 'ERROR: Unable to open file.<br>'; exit;}

foreach ($activemembers as $key => $line)

  {

    rtrim($line, "\n");

    if ($line != " ")

      {

        list($user_id, $iponfile, $timestamponfile, $coloronfile, $passwordonfile, $session_id) = explode("|", $line);

        trim($user_id);

        echo "<tr><td><a onclick=\"window.open('http://www.***.com/page/options.php?user_id=$user_id&session_id=$session_id','options','width=590,height=200,toolbar=no,scrollbars=yes,resizable=yes,statusbar=no,directories=no,menubar=no,location=no');return false;\" href=\"\">$user_id</a></td></tr>";

      }

  }

 

As can be seen, I've added trim before outputting the hyperlink, hoping it would solve the space problem.. but the problem still persists

 

If I replace user_id=$user_id .. with something like .. user_id=hello .. the space vanishes

 

Am I using trim correctly?.. I'll admit to not having checked properly yet

Just checked and it's ok.. isn't it?

 

All I can guess is.. could it be a server issue?! .. the session_id variable isn't effected, I'd have thought even if there's a gap in the data it'd get removed

 

Unless there's an invisible character (such as a new line or something) to the left of the first variable that trim isn't removing??  :shrug:

 

I know I should use mysql or something.. I'm planning on learning that soon instead of relying on flat files.. lol

 

Thanks for help to date and any more that can be given

I've just tested something else here to check if there really is a gap being added before $user_id .. and there must be .. even after trim is used!!

 

I added this bit of experimental, temporary code.. which follows the use of trim..

 

trim ($user_id);

echo "the user id is$user_id";

 

The output should be "the user id isEejut" (assuming my name is the user id).. but it outputs.. "the user id is Eejut"

 

I then tried this instead..

 

trim ($user_id);

echo "$user_id$user_id";

 

.. and the output is "Eejut Eejut" (yes, with a space.. and id is repeated on the same line.. therefore it can't be a new line.. can it?!)

 

So.. for some bizarre reason trim is either being ignored or isn't trimming.. why could this be?? lol

If this problem occurs with every user_id that is in your 'activemembers.txt' file, then you have a systematic problem with how you are producing or storing information in that file (and please be advised if the 'activemembers.txt' file is in a 'public' web accessible folder, that anyone who guesses the file name can browse to it and get all your member information.)

 

If you cannot determine what character is present in the data that is causing the problem, make a test version of 'activemembers.txt' that only has one entry in it with dummy data. If the test file produces the symptom, attach the file to a post so that someone can examine what is actually in it.

 

Best guess is that you are using a Word Processor to edit the file (or you copied/pasted from a Word Processor) and the underlying formatting characters that the Word Processor uses in the file is what is causing the problem.

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.