-2

I'm using a javascript step sequencer that records the current user-inputed drum pattern into the URL.

So for example before any user input the url looks like:

http://localhost:8888/member-index.php#/0000/0000/0000/0000/0000/0000/0000

and then if the user inputs a basic drum beat the URL might look like:

http://localhost:8888/member-index.php#/8020/0808/aaaa/0000/0000/0000/0000

So I want to be able to save the user-created patterns to my MySQL database so that user's can save and load beats they've previously created.

Could someone give me a quick example of what the PHP code would look like to save the pages current URL to a database?

EDIT:

People are saying to use $_GET - how would I use this with a URL like mine that is broken up into seven sections with "/" dividing them?

Ian McGinley
  • 11
  • 1
  • 5
  • Why not use `$_GET` variables instead of the URL string itself? This is the kind of thing they're designed for. – ASGM Apr 15 '13 at 18:15

2 Answers2

0

You could use htaccess and url rewriting to redirect all requests to a specific php in which you check the url. see:Rerouting all php requests through index.php

nevertheless I think using get/post or the request body is easier to send your data.

Community
  • 1
  • 1
Menelaos
  • 23,508
  • 18
  • 90
  • 155
0

Short Answer

Use $_GET instead.

Long Answer

Retrieving the url with PHP isn't going to include what comes after the #, because that's only sent to the browser and not to the server. As @Kazar says in an answer to a similar question, you could use Javascript and document.location.hash to retrieve the information after the hash and then send it to the server via ajax.

But fortunately there's a much better built-in solution, which is $_GET (documentation here).

Instead of constructing your url thus:

member-index.php#/8020/0808/aaaa/0000/0000/0000/0000

Make it like this:

member-index.php?a=8020&b=0808&c=aaaa&d=0000&e=0000&f=0000&g=0000

Then you can retrieve this information easily in PHP:

$a = $_GET['a'];
$b = $_GET['b'];
...

And then pass it on to the database. (Even better, replace a, b, etc. with whatever the order actually means)

Community
  • 1
  • 1
ASGM
  • 11,051
  • 1
  • 32
  • 53
  • well if he really wants to he could use htaccess and reroute all traffic to a specific php – Menelaos Apr 15 '13 at 18:29
  • There are all sorts of ways he could decide to pass variables through the url string, but as far as I know this is the way it's meant to be done in php. – ASGM Apr 15 '13 at 18:33
  • I figured out how to make the code appear as "http://localhost:8888/member-index.php#/a=ff00/b=0c00/c=0200/d=0000/e=0000/f=0000/g=0000" would I still be able to do it this way? – Ian McGinley Apr 15 '13 at 18:56
  • No; if you want to use `$_GET` you need to format it according to [the specifications](http://php.net/manual/en/reserved.variables.get.php). How are you generating the url in the first place? – ASGM Apr 15 '13 at 19:10