Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6197189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:46:32+00:00 2026-05-24T03:46:32+00:00

Having a problem here…. I can’t seem to find a good way to ‘add’

  • 0

Having a problem here….

I can’t seem to find a good way to ‘add’ and ‘subtract’ $variables to an URL string….

Here is my example:

in the url I have http://mywebsite.com/index.php?y=2011

For source code I have:

$currentPage = $_SERVER['PHP_SELF'];

Then if I want to add different $variables to the url string, I have been trying this…:

    echo '<a href="$currentPage.&t=col">College</a>';

But it isn’t keeping the value of the current URL.. .?

It displays : http://mywebsite.com/index.php?&t=col

Instead of : http://mywebsite.com/index.php?y=2011&t=col (doesn’t keep the $y variable)

I also need to find a way to change the $y and $t variable by any links, so I can easily change it to 2010, or 2009, with keeping the current $t variable.. ???

Thanks in advance!

HERE IS What I came up with from the great help!!!

$url = "http://www.mywebsite/index.php?";
foreach($_GET as $key=>$val){
$url.="$key=$val&"; }
echo '<a href="' . htmlspecialchars($url . 't=col') . '">College</a>';
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:46:33+00:00Added an answer on May 24, 2026 at 3:46 am

    As you may know, all variables passed through an URL are available in the $_GET array.
    Therefore, you can set up your link with something like this:

    $url = "http://site.com/index.php?";
    foreach($_GET as $key=>$val){
    $url.="$key=$val&"; }
    

    This gives you the benefit of also checking for certain variables and removing some that might be added by the user maliciously. And it also allows you to change your variables accordingly, as $key will contain either t or y

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I'm having a really basic problem here but I can't seem to
Here's the problem I'm having, I've got a set of logs that can grow
I am Having a problem here.I am downloading the excel sheet using Url and
I'm having a problem here. How you can see on the code below, I
I'm having the problem described here: http://groups.google.com/group/microsoft.public.xml.soap/browse_thread/thread/029ee5b5d4fa2440/0895d73c5c3720a1 I am consuming a Web Service using
I'm having a strange problem here... I have an ASP.NET 3.5 application that has
I'm having a bit of a problem here. We have 2 urls let me
I'm having a problem adding a reference to a .NET assembly I built. Here's
I'm having a little bit of trouble understanding what the problem is here. I
Ok, so here's the full description of the problem I'm having: I am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.