Jump to content

rawurlencode issue


OAFC_Rob

Recommended Posts

Hey people just been watching a php tutorial that mentions using rawurlencode for the links, ive pretty much followed th tutorial to the later bar using different pages, see coding below. However, it just doesnt work bringing back that object was not found  :confused:

 

Any ideas whats going wrong or why it isn't working?

 

		<?php
			#retrive from database and do a foreach loop maybe.
			$urlPage = "loginArea/login.php";
                                $param1 = "robert"; 

			$url = "http://localhost/duff3/";
			$url .= rawurlencode($urlPage);
                                $url .= "?userId=" . urlencode($param1);

		?>
                    
                         <ul class="menu">                                                                               
                             <li><a href="<?php $_SERVER["DOCUMENT_ROOT"] ?>/duff3/index.php" class="nav_selected"> home </a></li>
                             <li><a href="test.php?id=1" class="nav"> bio</a></li>
                             <li><a href="<?php echo htmlspecialchars($url); ?>" class="nav"> publicity</a></li>
                             <li><a href="" class="nav"> recordings</a></li>
                             <li><a href="" class="nav"> contact </a></li>
                        </ul>

Link to comment
Share on other sites

rawurlencode() will encode slashes. The result is that Apache thinks the link is to a file named "loginArea/login.php" (which is not the same as the "login.php" file in the "loginArea" directory).

 

In the code you've posted there is no need to use rawurlencode() anywhere.

Link to comment
Share on other sites

You would use rawurlencode() for paths in a URL, but for the individual names - not an entire chunk of it. Only only if you don't know that the name is valid in that part of a URI.

 

Your path is //localhost/duff3/loginArea/login.php. You know that for sure. Since it's URL-valid (ie, no unusual characters) you don't have to do anything to it.

If you didn't know for sure then you might use rawurlencode() for directory and file names.

"//localhost/" . rawurlencode($base_directory) . "/" . rawurlencode($sub_directory) . "/" . rawurlencode($submit_filename)

 

With that all said, I have never used rawurlencode() for anything. urlencode, a similar function with a similar use, is much more common.

Link to comment
Share on other sites

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.