how to get value from one page into another page via URL through session in PHP


I am new in PHP and I am doing some work I have two Page 1) link.php 2) golink.php


<li><a href="golink.php">Home</a></li>
<li><a href="golink.php">About us</a></li>
<li><a href="golink.php">Highlights</a></li>
<li><a href="golink.php">Price</a></li>
<li><a href="golink.php">Location Map</a></li>
<li><a href="golink.php">Payment Plan</a></li>

When I click any link, I want to get the name of that link in golink.php page. Example:- If I click Home link, I need to get Home value in golink.php page. I dont want to pass id value in href link like<a href="golink.php ? value= home">Home</a>
I want any other method like session. Please help me. Thanks in advance.




use the $_SERVER['HTTP_REFERER']. It will show the previous url.

<?php echo $_SERVER['HTTP_REFERER'] ?>



Unfortunately the HTTP_REFERER value will not help him... You could mess around by using hidden forms to pass a POST variable, but it's truly not worth it (messy, just not how it should be done).

I'd strongly recommend using a simple elegant (obvious) solution, especially since your new to php and don't want to form too many bad habits early on ;)




Possible with Javascript.

Example with Javascript and a cookie

$("a[href='golink.php']").on("click", function(event){
    document.cookie = "linkname="+ escape($(this).text());

This uses jquery and makes it easier to read. Still not the best solution. Since the visitor needs JS and Cookies enabled. The Skript creates a cookie called "linkname" and you can read the value in golink.php with $_COOKIE['linkname'] Best solution is really a query.

_COOKIE docs at

People are also looking for solutions to the problem: php - Jquery i want Same effect again and again on every click


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.