php document url with parameters in url does not work - php

I´ve got an url like this www.example.com/v=12345. This will go to my index.php site on my webserver and the variable 'v' is used to do some javascript stuff, which works fine.
Now i want to link to the document 'newsite.php" like this or similar: www.example.com/newsite.php/v=12345. This does not work since the css does not work anymore and i don't know why.. If i do it like www.example.com/newsite.phpv=12345 , the variable is read correctly but it opens the index.php again.. How can i do this correctly?
Thanks guys!

You should pass php variable in url as parameter like this:
www.example.com?v=12345
and in your php just get this value by:
$_GET['v']
It should solve your problems :)

Variables need the seperator ? between url and variable. And if you have more Variables, the variables are seperated with a &
Example:
www.domain.com/?v=123
www.domain.com/script.php?v=123
www.domain.com/?v=123&y=456
And every variable will be available via $_GET[]
$_GET['v']
$_GET['y']

Related

How To Put 2 PHP Variables On Url Without Using '&'

Let me explain with an example:
I have this link (php file): http:// mywebsite.com/abc/?id=fasfsa&id2=derp
On the Php I have the 2 variables id and id2.
So I'm using another php file to post the link but he has other variables and it doesn't consider mine.
Let me show how:
http: //website.com/publish.php?url=http: //mywebsite.com/abc/?id=fasfsa&id2=derp&linkname=blabla&image=http: //google.com/g.jpg
This is the sintax of publish.php. I can't edit that file. when I publish my link it shows only http:// mywebsite.com/abc/?id=fasfsa
It doesn't show the variable 'id2'. Anyone knows a method?
It doesnt show the variable id2 because it takes only his variables (url,linkname,image). I want to put all the link on the variable url .

Extend a link with get variables

I have this link:
www.something.com/index.php?page=teams
I then have this link:
Profile
I want to achieve is this link:
www.something.com/index.php?page=teams&profile=5
But I get this instead:
www.something.com?profile=5
The tricky part is that I can't just write the whole "path" like this:
Profile
Because it isn't always on the page 'teams'.
It might be a pretty stupid question, but i can't really figure it out.
You must include the page=teams parameter in the href.
Instead of
Profile
Something like
Profile
If that link is static you must need to update the html file.
But if page=anyvalue then you must generate the href link dynamically in your php code
for example:
Where $page is the current page, e.g $page="teams"
Well, you can just add it to the query string using http_build_query:
$newQueryString = http_build_query(['profile' => 5] + $_GET);
And then output it to your link:
Profile
Try something like this:
echo '<a href="'.{$_SERVER['SCRIPT_NAME']}.{$_SERVER['QUERY_STRING']}
.'&profile=5">Profile</a>
This makes use of $_SERVER to get the current page name (SCRIPT_NAME) and the existing query string (QUERY_STRING), and then appends "&profile=5" onto the end.
Well i have sort of fixed it.... i created a session called page, so i can access it everywhere. The thing is i can't get the variable $_GET['page'] because it's inside a included file called search.php, therefore i created the session.. But thanks for you suggestions guys!

Use link url upon click in PHP

I want to use the URL of the link that was clicked in a VB.net program. How can I take the url from my browser url bar and use it in my PHP program?
Example:
VB.net - click link then open using a web browser
url: www.something.com/id=^%$##&var2=13lfhd3f4gt
PHP - put the link in a variable or something so that I can use explode command to get the id and var2 from the URL itself
I need those variables to output a certain value from my database.
This question has the answer that you are looking for, for getting the url in PHP:
Get the full URL in PHP
Though for getting id and var2, it would be simpler to just use the $_GET variable in php. Then you don't have to explode the url and process it. Just change the '/' after 'com' to a ? like:
www.something.com?id=^%$##&var2=13lfhd3f4gt
You can do this using eg. $_SERVER global variable. Please refer to the manual

GET method in php clean URL

I have successfully created clean url for my project.. now what i need to do is add variables to URL..
localhost/user1/file?action=add
localhost/user2/file2?action=delete
where user and file are already rewritten i dont want it to be like localhost/user/file/add because localhost/user/folder/file will be mistaken to to the action parameter.. please help
Try using the ampersand instead of question mark:
localhost/user2/file2&action=delete
In your htaccess, the rewrite rule might look something like this:
RewriteRule ^user([0-9]+)/file([0-9]+)$ /page\.php?user=$1&file=$2
As you can see, the question mark is already there even though it is masked in the address bar. Appending another variable to the query string would require the ampersand for successful concatenation.
You need to get the url and start parsing the url from the question mark. I would save the contents then to an array, so that you've got a key and a value.
$uri = $_SERVER["REQUEST_URI"];
$questionMark = explode('?',$uri);
$questionMark[1] is the action=delete then. There are probably better ways then using explode() method here, but I just wanted to show how you get the string.
You can read GET variables in PHP by accessing the global $_GET array:
http://php.net/manual/en/reserved.variables.get.php
In your example, the php file that is used for handling files would be able to read in:
echo $_GET['action']; // 'add' or 'delete'

get URL in php IN INCLUDE FILE

i have some problem i try to get the uri in php.
I'm using:
$_SERVER['REQUEST_URI']
It works just fine if i do it in the index.php, but, i NEED to get the url in a include file, but, when i do it, it takes the FILE adress, i mean, it shows something like this
adress bar: www.webpage.com/index.php
$_SERVER['REQUEST_URI'] output: webpage/includefile.php
I am explaining myself here? Thanks!
How are you including the file? If it's being included via an HTTP reference then it's actually being served as a page and the functionality you are seeing is correct. If the include path is a local file, you shouldn't be seeing this behaviour
Found this whilst trying to solve the same issue.
My solution that worked is to use $_SERVER['HTTP_REFERER']
This worked well in that it also included the parameters (e.g. ?this=that&foo=bar)
Maybe somewhere in your code (or in another include file) the value is overwritten.

Categories